Tar
Membackup Isi Folder
Pindah ke directory tempat file-file yang akan di backup berada. Kemudian ketik:
$ tar cvf backup.tar .
Misalnya akan keluar
./ picture.jpg doucment.doc database.db tar: backup.tar is the archive; not dumped
Catatan:
c=create (an archive) v=verbose (just because) f=filename (the name of our tarball) .=current directory (what's going to be backed up)
Also worth mentioning is that by default tar is recursive- meaning it will back up all files and subdirectories recursively unless you otherwise specify with the n flag (non-recursive)
Melihat Isi tar
The current directory will now contain a file called backup.tar. To display the contents of the tarball file, we could issue this command:
$ tar tvf backup.tar
Akan keluar kira-kira
drwxr-xr-x root/gci 0 Jun 29 10:10 ./ -rw-r--r-- root/gci 1 Jun 29 10:10 picture.jpg -rw-r--r-- root/gci 1 Jun 29 10:10 document.doc -rw-r--r-- root/gci 1 Jun 29 10:10 databse.db
Catatan:
t=table of contents (list) v=verbose (display all info) f=filename (backup.tar)
Membuka Isi tar
To extract the entire contents of the tarball to the current directory, we can type:
$ tar xvf backup.tar
./ picture.jpg doucment.doc database.db
Catatan:
x=extract v=verbose f=filename (backup.tar)
To extract only the picture.jpg file from the archive, type the following command:
$ tar xvf backup.tar picture.jpg
Alternatively, you can use wild cards in either the creation or extraction of a tarball. To extract all jpg files from our archive, we can use a command like this:
$ tar xvf backup.tar *.jpg
Menggunakan Kompresi
If you would also like to add compression to your tarballs, you can combine the gzip utility with tar on the command line by adding the z switch to the command. Usually when this is done, we change the suffix of our tarball filename from .tar to either .tgz or .tar.gz. This will let whoever sees the file know that it is a gzipped tarball.
$ tar zcvf tarball.tgz .
Catatan:
z=gzip compression c=create v=verbose f=filename (backup.tgz) .=current directory (what to backup)
[Permissions with tar]
If you would like to preserve the permissions of the files you backup, use the p option with the tar command. This will save the uid, gid as well as the specific permission attributes of the files (read, write, execute etc.)
$ tar pzcvf tarball.tgz .
You should also use the p option with the tar extraction command:
$ tar pxvf tarball.tgz .
[Using tar with a Tape Drive]
I use tar in conjunction with my Seagate DAT drive. If you issue any of the previous commands in this HOW-TO without the f option and a tarball filename, you will find that tar will default to writing the files to the device /dev/rsa0 (raw sequential access device 0). Basically this is your first SCSI tape drive. If you have more than one tape drive you would like to use, you can issue the f option and the device name (rsa0, rsa1 etc.) of your specific tape drive instead of a filename.
Examples: Backing up the current directory to Tape:
$ tar cv . <- default tape drive (rsa0)
$ tar cvf /dev/rsa1 . <- second tape drive (rsa1)
Restore files from Tape:
$ tar xv . $ tar xvf /dev/rsa1
So, there are the basics of tar. If you would like more information on the tar command, try the man pages.
man tar