How to make backup copies with GNU tar ?

Author: Razvan MIHAIU (please remove '_rem' and 'rem_')
Date: 17/01/2001

The tar (tape archiver) application can be used to make backup copies of your data.

A practical example seems to be the best way to start this small essay. In order to make a backup copy of the /etc directory a user should type:

tar --create --file=backup.tar /etc

Later the archive can be compressed with gzip or bzip2. Bzip2's algorithms are more efficient, therefore its use is encouraged over gzip.

gzip -9 backup.tar bzip -9 backup.tar

The parameter ' -9 ' instructs the archiver to achieve the best compression it can.

Both archiving and compression can be achieved in one step:

tar --create --gzip --file=backup.tar.gz /etc tar --create --bzip2 --file=backup.tar.bz2 /etc

Additionally you can also save the absolute access paths and the file access rights:

tar --create --gzip --absolute-names --preserve-permissions --file=backup.tar.gz /etc tar --create --bzip2 --absolute-names --preserve-permissions --file=backup.tar.bz2 /etc

One nice thing to do would be to automatically generate the name of the backup file from the current date:

tar --create --bzip2 --file=backup-`date +"%b_%d_%Y"`.tar.bz2 /etc

When inflating the archive, the owners of the files can be restored with the '--same-owner' parameter. For the superuser this is the default behaviour:

tar --extract --gzip --absolute-names --preserve-permissions --same-owner --file=backup.tar.gz tar --extract --bzip2 --absolute-names --preserve-permissions --same-owner --file=backup.tar.bz2

Additionally the "--verbose" parameter can be specified in order to get more information about the executing operation.

For a detailed explanation of tar's parameters you should check the info manual - 'info tar'.

If you wish to add something feel free to use the forums.

Best regards,
17/01/2001 - Mohammedia, Morocco

Razvan Mihaiu � 2000 - 2023