The tar backup program is an archiving
program designed to store and extract files from an archive
file known as a tarfile. A tarfile may be made on a tape
drive; however, it is also common to write a tarfile to a
normal file.
If you want to know more options about tar
click here
Making backups
with tar
A full backup can easily be made with tar:
# tar --create --file /dev/ftape
/usr/src
tar: Removing leading / from absolute path names in
the archive
The example above uses the GNU version of tar and its long
option names. The traditional version of tar only
understands single character options. The GNU version can
also handle backups that don't fit on one tape or floppy,
and also very long paths; not all traditional versions can
do these things. (Linux only uses GNU tar.)
If your backup doesn't fit on one tape, you need to use the
--multi-volume (-M) option:
# tar -cMf /dev/fd0H1440
/usr/src
tar: Removing leading / from absolute path names in
the archive
Prepare volume #2 for /dev/fd0H1440 and hit return:
Note that you should format the floppies before you begin
the backup, or else use another window or virtual terminal
and do it when tar asks for a new floppy.
After you've made a backup, you should check that it is OK,
using the --compare (-d) option:
# tar --compare --verbose
-f
/dev/ftape
usr/src/
usr/src/linux
usr/src/linux-1.2.10-includes/
Failing to check a backup means that you will not notice
that your backups aren't working until after you've lost the
original data.
An incremental backup can be done with tar using the --newer
(-N) option:
# tar --create --newer '8 Sep 1995'
--file /dev/ftape /usr/src
--verbose
tar: Removing leading / from absolute path names in
the archive
usr/src/
usr/src/linux-1.2.10-includes/
usr/src/linux-1.2.10-includes/include/
usr/src/linux-1.2.10-includes/include/linux/
usr/src/linux-1.2.10-includes/include/linux/modules/
usr/src/linux-1.2.10-includes/include/asm-generic/
usr/src/linux-1.2.10-includes/include/asm-i386/
usr/src/linux-1.2.10-includes/include/asm-mips/
usr/src/linux-1.2.10-includes/include/asm-alpha/
usr/src/linux-1.2.10-includes/include/asm-m68k/
usr/src/linux-1.2.10-includes/include/asm-sparc/
usr/src/patch-1.2.11.gz
Unfortunately, tar can't notice when a file's inode
information has changed, for example, that its permission
bits have been changed, or when its name has been changed.
This can be worked around using find and comparing current
filesystem state with lists of files that have been
previously backed up. Scripts and programs for doing this
can be found on Linux ftp sites.
12.4.2. Restoring files with tar
The --extract (-x) option for tar extracts files:
# tar
--extract --same-permissions
--verbose --file
/dev/fd0H1440
usr/src/
usr/src/linux
usr/src/linux-1.2.10-includes/
usr/src/linux-1.2.10-includes/include/
usr/src/linux-1.2.10-includes/include/linux/
usr/src/linux-1.2.10-includes/include/linux/hdreg.h
usr/src/linux-1.2.10-includes/include/linux/kernel.h
You also extract only specific files or directories (which
includes all their files and subdirectories) by naming on
the command line:
# tar xpvf /dev/fd0H1440
usr/src/linux-1.2.10-includes/include/linux/hdreg.h
usr/src/linux-1.2.10-includes/include/linux/hdreg.h
Use the --list (-t) option, if you just want to see what
files are on a backup volume:
# tar --list --file
/dev/fd0H1440
usr/src/
usr/src/linux
usr/src/linux-1.2.10-includes/
usr/src/linux-1.2.10-includes/include/
usr/src/linux-1.2.10-includes/include/linux/
usr/src/linux-1.2.10-includes/include/linux/hdreg.h
usr/src/linux-1.2.10-includes/include/linux/kernel.h
Note that tar always reads the backup volume sequentially,
so for large volumes it is rather slow. It is not possible,
however, to use random access database techniques when using
a tape drive or some other sequential medium.
tar doesn't handle deleted files properly. If you need to
restore a filesystem from a full and an incremental backup,
and you have deleted a file between the two backups, it will
exist again after you have done the restore. This can be a
big problem, if the file has sensitive data that should no
longer be available.