What is TAR?
Tar (Tape archive) allows you to very easily, safely backup in Linux. If you have a small data to backing up it’s not a big deal. But if you want to backup large amount of data, yup it’s also easy but it’s take some time but not a big deal.
Backup Files Using TAR Archive
The first thing you need to do is type a command tar and we can take a backup. But there are some options we require to backup using tar, so we’ll discuss it firstly.
*** tar -option destination file source file
[root@techbrown]# tar -cvpf /etc.tar /etc
[root@techbrown ~]# ls /
bin dev file.txt lost+found opt sbin sys var
boot etc home media proc selinux tmp
cgroup etc.tar lib mnt root srv usr
c -> create or override a backup file.
v -> Verbose (tell you what is going on during this process).
p -> preserving permission ( it is useful, if you are creating backups of web server and don’t put lowercase p, tar will not take it and we will face some problem while recovering data regarding permission. So after that recovery you need to go back and set permission and all that stuff once again. So keep this in mind that putp while taking backups.)
f -> Lowercase f is allow you to give tar a file name to create backup.
/etc.tar -> File name were you want to backup you data.
/etc -> The original data.
[root@techbrown]# du -sh /etc
To check the size of a file.
[root@techbrown]# file /etc
To check the file system of a file.
And now to compress file nearly about 70% to compress already compress file, there we use some tools, these are following,
- gzip
- bzip2
- gzip
[root@techbrown]# gzip /etc.tar
[root@techbrown ~]# ls /
bin dev file.txt lost+found opt sbin sys var
boot etc home media proc selinux tmp
cgroup etc.tar.gz lib mnt root srv usr
To unzip gzip compression
[root@techbrown ~]# gunzip /etc.tar.gz
bzip
[root@techbrown ~]# bzip2 /etc.tar
[root@techbrown ~]# ls /
[root@techbrown ~]# du -sh /etc.tar.bz2
Powerful than gzip.
To unzip bzip2 compression
[root@techbrown ~]# bunzip2 /etc.tar.bz2
To extract TAR
[root@techbrown ~]# tar -xvf /etc.tar
[root@techbrown ~]# tar -xvf /etc.tar -C /root
x-> To extract.
C-> Destination folder
[root@techbrown ~]# ls root
To check file without extraction.
[root@techbrown ~]# tar -tvf /etc.tar
t-> List file in /etc.tar
Bzip and Gzip using TAR
[root@techbrown ~]# tar -cvpzf /sbin.tar.gz
[root@techbrown ~]# tar -cvpjf /bin.tar.bz2 /bin
To extract
[root@techbrown ~]# tar -xvf /bin.tar.bz
Congratulations your Backup files are saved on TAR Archives.
Comments