With an impressive array of options (see the man page), tar is quite flexible
and powerful in combination with shell scripts. With the -z option, it can
even create and restore gzip compressed archives, and the -j option works
with bzipped files.
Creating Full and Incremental Backups with tar
If you want to create a full backup, the following creates a bzip2
compressed tarball (the j option) of the entire system:
Click here to view code image
matthew@seymour:~$ sudo tar cjvf fullbackup.tar.bz2 /
To perform an incremental backup, you must locate all the files that have
been changed since the last backup. For simplicity, assume that you do
incremental backups on a daily basis. To locate the files, use the find
command:
Click here to view code image
matthew@seymour:~$ sudo find / -newer name_of_last_backup_file ! -a –
type f –print
When run alone, find generates a list of files system-wide and prints it to
the screen. The ! -a -type eliminates everything but regular files from
the list; otherwise, the entire directory is sent to tar, even if the contents
were not all changed.
Pipe the output of the find command to tar as follows:
Click here to view code image
matthew@seymour:~$ sudo find / -newer name_of_last_backup_file ! –
type d -print |\
tar czT - backup_file_name_or_device_name
Here, the T - option gets the filenames from a buffer (where the - is the
shorthand name for the buffer).
NOTE
The tar command can backup to a raw device (one with no file system)
and to a formatted partition. For example, the following command backs up
those directories to device /dev/hdd (not /dev/hda1, but to the
unformatted device itself):
Click here to view code image
matthew@seymour:~$ sudo tar cvzf /dev/hdd /boot /etc /home