Securing-Optimizing-RH-Linux-1_2_452
Comments and suggestions concerning this book should be mailed to gmourani@videotron.ca
© Copyright 1999-2000 Gerhard Mourani and Open Network Architecture ®
452
Notice how a filename, which contains the current date, is derived, simply by enclosing the date
command between two back-quote characters. A common naming convention is to add a tar
suffix for non-compressed archives, and a tar.gz suffix for compressed ones. Since we aren't
able to specify a filename for the backup set, the "--label" option can be used to write some
information about the backup set into the archive file itself. Finally, only the files contained in the
"/home" are written to the tape.
Because the tape drive is a character device, it is not possible to specify an actual file name.
Therefore, the file name used as an argument to tar is simply the name of the device "/dev/st0",
the first tape device. The "/dev/st0" device does not rewind after the backup set is written;
therefore it is possible to write multiple sets on one tape. You may also refer to the device as
/dev/st0, in which case the tape is automatically rewound after the backup set is written. When
working with tapes, you can use the following commands to rewind, and eject your tape:
[root@deep /]# mt -f /dev/st0 rewind
[root@deep /]# mt -f /dev/st0 offline
Caution: To reduce the space needed on a tar archive, the backups can be compressed with the
z option of tar program. Unfortunately, using this option to compress backups can cause trouble.
Due to the nature of how compression works, if a single bit in the compressed backup is wrong,
all the rest of the compressed data will be lost. Its recommended to NOT using compression (the
z option) to make backups with the tar command.
·
If your backup doesn't fit on one tape, youll need to use the --multi-volume (-M) option:
[root@deep /]# cd /
[root@deep /]# tar cMpf /dev/st0 /home
Prepare volume #2 for /dev/st0 and hit return:
·
After you have made a backup, you should check that it is OK, using the --compare (-d)
option as show bellow:
[root@deep /]# cd /
[root@deep /]# tar dvf /dev/st0
·
To perform a backup of your entire system, use the following command:
[root@deep /]# cd /
[root@deep /]# tar cpf /archive/full-backup-`date '+%d-%B-%Y'`.tar \
--directory / --exclude=proc --exclude=mnt --exclude=archive \
--exclude=cache --exclude=*/lost+found .
The --directory option tells tar to first switch to the following directory path (the / directory in
this example) prior to starting the backup. The --exclude options tell tar not to bother backing up
the specified directories or files. Finally, the . character at the end of the command tells tar that it
should back up everything in the current directory.
Caution: When backing up your file systems, do not include the "/proc" pseudo-file-system! The
files in "/proc" are not actually files but are simply file-like links which describe and point to kernel
data structures, also do not include the /mnt, /archive, and all lost+found directories.
Automating tasks of backups made with tar
It is always interesting to automate the tasks of a backup. Automation offers enormous
opportunities for using your Linux server to achieve the goals you set. The following example
bellow is our backup script - named backup.cron. This script is designed to run on any computer
by changing only the four variables: COMPUTER, DIRECTORIES, BACKUPDIR, and TIMEDIR.