How to backup files using tar in Linux

Backup files using tar in Linux

  • Into information technology, a backup or the process of backup files using tar and making copies of data which may be used to restore the original after a data loss event.
  • Backups have two distinct purposes.
  • The primary purpose is to recover data after its loss, be it by data deletion or corruption.
  • The secondary purpose of backups is to recover data from an earlier time, according to a user-defined data retention policy, typicaall cconfigured within a backup application for how long copies of data are required.
  • Backup is most important job of a system administrator, as a system admin it is your duty to take backups of the data every day.
  • The easiest way to back up your files is just copying. But if you have too many files to backup, copying and restoring may take too long time and it is not convenient. If there is a tool that can put many files into one file, the world will be better. Fortunately , ‘Tar’ is used to create archive files. It can pack files or directories into a ‘tar’ file. It is like WinZip in windows, without much compression.
  • The Gzip program compress a single file. One important thing to remember about gzip is that, unlike tar, it replaces your original file with a compressed version. (The amount of compression varies with the type of data, but a typical text file will be reduced by 70 to 80 precent)

A Typical scenario of backup and compression using tar and gzip

backup files using tar


How to take backup files using tar

TO backup the file using tar the syntax is

# tar –cvf <destination and name to be> <Source file>

#tar –cvf /opt/etc.tar /etc

 

Check the size of tar file by using du –h <file name> command.

#du –h /opt/etc.tar

Apply gzip on tar file and check the size.

For apply gzip on a tar file use the following file.

#gzip <file name>

#gzip /opt/etc.tar

 

Now check the size of the file.

 

Now transfer the file to other system and remove gzip and tar from it and check the size on every step.

Let’s transfer the file to other computer using scp

#scp /opt/tec/tar.gz 192.168.10.10:/root/

 

Login to the remote system, remove gzip it and check the size.

To gzip a file the syntax is

#gunzip <file name>

#gunzip etc.tar.gz

 

Now Untar the file and check for the size of the file/directory

To untar a file use following syntax

#tar –xvf <file name>

#tar –xvf etc.tar

 

4 thoughts on “How to backup files using tar in Linux”

  1. I was recommended this web site by my cousin. I am no longer positive whether or not this post is written through him as no one else recognise such designated approximately my difficulty. You are incredible! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *