Skip to content

Tar Backup – Watchout

April 11, 2012

Be careful while taking the TAR Backup.
While restoring the file to different location from TAR backup, you may end up overwrite the existing file.
So be-careful with method you follow to backup as below .
============================================================
File 1)
=========
cat file1.txt
contents of file1.txt
 
File 2)
=========
cat file2.txt
contents of file2.txt
 
maldevsrv:/opt/oracle: ls -ltr *.txt
-rw-r–r–   1 oracle   dba           24 Feb 19 06:45 p.txt
-rw-r–r–   1 oracle   dba           22 Apr 10 09:44 file1.txt
-rw-r–r–   1 oracle   dba           22 Apr 10 09:45 file2.txt
 
 
We will take the Tar backup in two ways:
=========================================
1) Without providing the full path of file(s)/dir of which we need to backup.         
 
(This backup is Safe, and can be restored which ever directory you need.)
 
cd /opt/oracle
 
maldevsrv:/opt/oracle: tar -cvf demo1.tar *.txt
a file1.txt 1K
a file2.txt 1K
a p.txt 1K
 
 
2) Providing the full path of file(s)/dir of which we need to backup.                       
 
(This backup is Not Safe, and cannot be restored which ever directory you need, Not safe because while restoring it overwrites to original files/location.)
 
maldevsrv:/opt/oracle: tar -cvf demo2.tar /opt/oracle/*.txt
a /opt/oracle/file1.txt 1K
a /opt/oracle/file2.txt 1K
a /opt/oracle/p.txt 1K
 
 After backup I have added more contents to file2.txt as below
==============================================================
 
maldevsrv:/opt/oracle: cat file2.txt
contents of file2.txt
Hello I am new Content
 
===============================================================
Now we will try Restoring the above tar’s in /tmp/SR and see what happens.
===============================================================
 
1) We will use first tar file (demo1.tar)that was backed up without giving full path, and see if its restoring to required directory (/tmp/SR).
 
maldevsrv:/opt/oracle: cd /tmp/SR
 
maldevsrv:/tmp/SR: tar -xvf /opt/oracle/demo1.tar
tar: blocksize = 8
x file1.txt, 22 bytes, 1 tape blocks
x file2.txt, 22 bytes, 1 tape blocks
x p.txt, 24 bytes, 1 tape blocks
 
maldevsrv:/tmp/SR: pwd
/tmp/SR
 
maldevsrv:/tmp/SR: ls -ltr
total 48
-rw-r–r–   1 oracle   dba           24 Feb 19 06:45 p.txt
-rw-r–r–   1 oracle   dba           22 Apr 10 09:44 file1.txt
-rw-r–r–   1 oracle   dba           22 Apr 10 09:45 file2.txt
 
maldevsrv:/tmp/SR: cat file2.txt
contents of file2.txt
 
As you see file2.txt is restored to required directory /tmp/SR and it worked well as expected.
 
 
maldevsrv:/tmp/SR: cat /opt/oracle/file2.txt 
contents of file2.txt
Hello I am new Content
 
The original file file2.txt with latest contents, i.e. while restoring it did not overwrite the original files.
 
 
2) Now we will use second tar file (demo2.tar ) that was backed up giving full path, and see if its restoring to required directory (/tmp/SR) or Overwriting the original files.
 
Just cleaning up files that were restored from demo1.tar
=========================================================
maldevsrv:/tmp/SR: pwd
/tmp/SR
maldevsrv:/tmp/SR: rm *.txt
 
maldevsrv:/tmp/SR: ls -ltr
total 0
 
Now restoring the files from demo2.tar
========================================
maldevsrv:/tmp/SR: pwd
/tmp/SR
 
maldevsrv:/tmp/SR: tar -xvf /opt/oracle/demo2.tar
tar: blocksize = 8
x /opt/oracle/file1.txt, 22 bytes, 1 tape blocks
x /opt/oracle/file2.txt, 22 bytes, 1 tape blocks
x /opt/oracle/p.txt, 24 bytes, 1 tape blocks
 
maldevsrv:/tmp/SR: ls -ltr                  
total 0
 
So it did not restore to expected directory (/tmp/SR), instead it restored to original directory from where the files got backed up.
 
maldevsrv:/tmp/SR: cat /opt/oracle/file2.txt 
contents of file2.txt
 
This show’s the latest file (file2.txt) in /opt/oracle, was overwritten with restored file.
 
 
Conclusion: Always take Tar backup without providing the full path, This will avoid accidental restore from overwriting the original files.
 
E.g
 
1) To Backup Oracle Home
==============================
export BACKUP_DIR=/u01/orasoft/orabin_bkp
 
maldevsrv:/opt/oracle: echo $ORACLE_HOME
/u01/app/oracle/product/11.2.0maldevsrv:/opt/oracle: cd $ORACLE_HOME/..

maldevsrv:/u01/app/oracle/product: pwd
/u01/app/oracle/product

maldevsrv:/u01/app/oracle/product: ls -ltr
total 6
drwxr-sr-x  75 oracle   dba         2048 Mar  6 08:44 11.2.0

nohup tar -cvf $BACKUP_DIR/`hostname`.oraHome.11.2.0.1.0.bkup.`date +\%d”.”\%m”.”\%Y”.”\%H”.”\%M”.”\%S`.tar 11.2.0 > $BACKUP_DIR/nohup.oraHome_CRS_11.2.0.1.0.bkup.`date +\%d”.”\%m”.”\%Y”.”\%H”.”\%M”.”\%S` &

2) To Take CRS HOME Backup Root user:
==========================================
export BACKUP_DIR=/u01/orasoft/orabin_bkp

maldevsrv:/opt/oracle: cd /u01/appmaldevsrv:/u01/app: ls -ltr
total 8
drwxr-xr-x  67 root     dba         2048 Apr  1 06:27 crs
drwxrwx—   6 oracle   dba         1024 Apr  1 06:29 oraInventory
drwxr-sr-x   9 oracle   dba         1024 Apr  9 04:35 oracle

nohup tar -cvf $BACKUP_DIR/`hostname`.oraHome_CRS_11.2.0.1.0.bkup.`date +\%d”.”\%m”.”\%Y”.”\%H”.”\%M”.”\%S`.tar crs > $BACKUP_DIR/nohup.oraHome_CRS_11.2.0.1.0.bkup.`date +\%d”.”\%m”.”\%Y”.”\%H”.”\%M”.”\%S` &

3) To Backup Central Oracle Inventory
========================================
export BACKUP_DIR=/u01/orasoft/orabin_bkp
maldevsrv:/opt/oracle: echo $ORACLE_BASE
/u01/app/oracle
maldevsrv:/opt/oracle: cd $ORACLE_BASE
maldevsrv:/u01/app/oracle: ls -ltr
total 6
drwxrwxr-x  11 oracle   dba         1024 Feb 27 02:44 diag
drwxr-sr-x   2 oracle   dba           96 Feb 27 03:04 checkpoints
drwxr-sr-x   5 oracle   dba         1024 Feb 27 08:16 emagent
drwxr-sr-x   5 oracle   dba         1024 Mar  6 05:42 cfgtoollogs
drwxr-sr-x   3 oracle   dba           96 Mar 30 08:46 product
drwxr-s—   4 oracle   dba           96 Apr  9 04:35 admin
drwxr-s—   3 oracle   dba           96 Apr  9 04:35 flash_recovery_area
maldevsrv:/u01/app/oracle: cd $ORACLE_BASE/..
maldevsrv:/u01/app: pwd
/u01/app
maldevsrv:/u01/app: ls -ltr
total 8
drwxr-xr-x  67 root     dba         2048 Apr  1 06:27 crs
drwxrwx—   6 oracle   dba         1024 Apr  1 06:29 oraInventory
drwxr-sr-x   9 oracle   dba         1024 Apr  9 04:35 oracle
nohup tar -cvf $BACKUP_DIR/`hostname`.oraInv.bkup.`date +\%d”.”\%m”.”\%Y”.”\%H”.”\%M”.”\%S`.tar oraInventory > $BACKUP_DIR/nohup.orainv.`date +\%d”.”\%m”.”\%Y”.”\%H”.”\%M”.”\%S` &
Advertisements

From → Oracle

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: