Sunday, October 2, 2016

File Backup using ‘tar’ command

The “tar” command stands for tape archive that generally used by system/database administrator to write archives directly to tape devices or can use it to create archives files on disk. The ‘tar’ program is easy to use and transportable having limits on file name size, won't backup special files, does not follow symbolic links, and doesn’t support multiple volumes. The main advantage is that ‘tar’ is supported every where or can be moved easily from one disk to another disk or machine to machine. It is also useful for copying directories.
The ‘tar’ program takes one of three function command line arguments:
c – to create a tar file
t – table of contents (see the name of all files)
x – extract (restore) the contents of the tar file.
In addition to above function command line argument these argument are useful:
f – Specifies filename
z – Use zip/unzip to compress the tar file or to read from a compressed tar file.
v – Verbose output, show the file being stored into or restored from tar file.
Example:
To tar all .arc and .ctf files into a tar file named data.tgz use:
tar cvzf data.tgz *.arc *.ctf
This will creates (c) a compressed tar file name data.tgz (f) and shows the file being stored into the tar file (v). The .tgz suffix is a convention for gzipped tar file.
To extract files from tar file
tar –xvf filename.tar
To tar up all files and directories under current directories or under PROD1 directory and writes files to filename.tar.
tar cvzf data.tgz shahid123
tar  -cvf  /tmp/filename.tar . 
tar  -cvf  /tmp/filename.tar  PROD1
It is often more useful to tar a directory (which tar all files and subdirectories recursively unless you specify other option)
To see a tar file table of contents
tar tzf data.tgz
To display only the content in tar binary file
tar –tvf filename.tar 
When file size is too large (more than 8GB), use –E option.

 tar -cvfE /data/oradata/tars/PROD1/large_file_blob.tar 

No comments:

Post a Comment