Monday, August 26, 2013

.::: How To Backup, Extract, Display Content files with Tar, Compress & extract using Gzip, Gunzip(.gz) :::.

Solaris tar command to backup data on tape device. Tar name come from Tape ARchiver. It is both a file format and the name of the program used to handle such file. Tar archive files have names ending in ".tar". If an archive is compressed, the compression program adds its own suffix as usual, resulting in filename endings like ".tar.Z", ".tar.gz", and ".tar.bz2". Tar doesn't require any particular filename suffix in order to recognize a file as an archive. Tar was originally created for backups on magnetic tape, but it can be used to create tar files anywhere on a filesystem. Archives that have been created with tar are commonly referred to as tarballs.

1. Creating a tarball/new set of backup.

To create a Tar file, use tar command as follows:
# tar -cvf <file_name_tar> <file/folderwilltar>

Where

    c – Create a new files on tape/archive
    v – verbose i.e. show list of files while backing up
    f – tape device name or file

Sample

root@teguht # ls
Teguh
root@teguht # tar -cvf Teguh.tar Teguh
a Teguh/ 0K
a Teguh/Teguh Triharto.doc 128K
a Teguh/Teguh Triharto_1.doc 128K
a Teguh/Teguh Triharto_2.doc 128K
root@teguht # ls
Teguh      Teguh.tar
root@teguht #


Remember c option should only use to create new set of backup.

2. Extracting Data from a Tarball restore tape backup taken with tar

Use tar command as follows to retrieve tape drive backup to current directory:

# tar -xvf <file_name_tar> <file/folderwillextracttar>

sample

root@teguht # ls
Teguh.tar
root@teguht # tar -xvf Teguh.tar
x Teguh, 0 bytes, 0 tape blocks
x Teguh/Teguh Triharto.doc, 131072 bytes, 256 tape blocks
x Teguh/Teguh Triharto_1.doc, 131072 bytes, 256 tape blocks
x Teguh/Teguh Triharto_2.doc, 131072 bytes, 256 tape blocks
root@teguht # ls
Teguh      Teguh.tar
root@teguht #

3. Displaying the Contents of a Tarball

root@teguht # tar tvf Teguh.tar
drwxr-xr-x   0/0        0 Aug 26 16:23 2013 Teguh/
-rw-r--r--   0/0   131072 Aug 26 16:23 2013 Teguh/Teguh Triharto.doc
-rw-r--r--   0/0   131072 Aug 26 16:23 2013 Teguh/Teguh Triharto_1.doc
-rw-r--r--   0/0   131072 Aug 26 16:23 2013 Teguh/Teguh Triharto_2.doc
root@teguht #

4. Compression Using Gzip

To create  tar.gz, use tar command as follows:
# gzip <file_name_tar> 

Sample  
root@teguht # ls
Teguh      Teguh.tar
root@teguht # gzip Teguh.tar
root@teguht # ls
Teguh         Teguh.tar.gz
root@teguht #

root@teguht # ls -lh
total 274
drwxr-xr-x   2 root     root         512 Aug 26 16:28 Teguh
-rw-r--r--   1 root     root        126K Aug 26 16:24 Teguh.tar.gz
root@teguht # du -sh Teguh
 553K   Teguh
root@teguht #

5. Extract tar.gz Using Gunzip

To create  tar.gz, use tar command as follows:
# gunzip <file_name_tar>

sample
root@teguht # gunzip Teguh.tar.gz
root@teguht # ls
Teguh.tar
root@teguht #
root@teguht # tar tvf Teguh.tar
drwxr-xr-x   0/0        0 Aug 26 16:23 2013 Teguh/
-rw-r--r--   0/0   131072 Aug 26 16:23 2013 Teguh/Teguh Triharto.doc
-rw-r--r--   0/0   131072 Aug 26 16:23 2013 Teguh/Teguh Triharto_1.doc
-rw-r--r--   0/0   131072 Aug 26 16:23 2013 Teguh/Teguh Triharto_2.doc
root@teguht #

No comments:

Post a Comment

Popular Posts