18 Backup strategy “He who does not plan for failure, plans to fail ”
18.1.3 Backup tools
A few backup tools have been selected here. Some fullfill different services to the others. The type of tool you will use may depend on the size of the system involved, the backup media and the skill of the user performing the backup (or the ability of the automated backup).
mt
mt controls a magnetic tape. By default, it will use the device /dev/tape, although you should make this a link to /dev/st0 or similar. mt provides a mechanism to rewind, retension, eject and erase a tape.
mt rewind # rewind /dev/tape
mt -f /dev/ht0 eject # eject /dev/ht0
mt erase # erase the tape
mt also provides a number of positioning and tape control commands. tar and cpio Tar stands for tape archiver. Tar is a well known and widely used archiving tool, orginally designed for tapes. The tool is quite often used to send compressed files over the internet. Review of tar command tar has three main functions:
Create Create a new archive tar c or tar create Extract Extract files from an archive tar x or tar extract List List contents of archive or test the
archive tar t or tar list
The following supplementary options that are commonly used together with the main options.
File Use a file name instead of stdin or stdout tar [c or x]f filename or
tar create file=filename Verbose Display information while processing
archive tar v or tar verbose
Use gzip Use gzip compression while either
extracting, listing or creating an archive tar z or tar gzip
Use bzip2 Use bzip2 compression while either
extracting, listing or creating an archive tar j (tar Ior in some versions of tar –bzip2 tar) Example13
tar -zcvf tarfile.tar.gz /usr/local/
This command will create a gzipped tar archive called tarfile.tar.gz of all the files in /usr/local
18 Backup strategy LPI 102 Course Notes 113
Backups with tar
When doing backups with tar it is useful to use some of the following features:
Multi Volume M or multivolume This allows you to make backups to multivolume media like multiple tapes of zip drives etc.
Volume Length L tapelength=N Not all tape drives report an end of tape correctly. It is often necessary to specify the size of the media. The tape lenght will be 1024xN.
New Volume Script F, info script=F, newvolumescript=F
You can run a script every time the tape changes. This script could be used to interact with an automated tape changer, or simply to ask the user to change the tape.
Verify Backup W, verify This option causes tar to attempt to verify the archive after writing it. Not all media support this option. Apend to Archive r apend This option works like the \cmd{c}, except that the
file is not overwriten, it is merely appended to.
Update Archive u update Updating an archive is similar to append except that newer files will overwrite files by the same name. Incremental using list g, listedincremental=F This option uses a list file to determine what files where last backed up and what their time stamp was. This method is very useful in a structured backup scenario.
Here we create archives using the file inc.status to store dates and times of files as we go.
% tar -c -l -g inc.status -f baseline.tar /etc
% touch /etc/motd
% tar -c -l -g inc.status -f inc1.tar /etc
% touch /etc/issue
% tar -c -l -g inc.status -f inc2.tar /etc
You will notice that the second incremental backup does not contain /etc/motd. Both backups contain all the directories however. tarfix The tarfix package contains tools that can handle corrupted tar files: • tarl is a tool to list the contents of of a corrupted tar file. • targ attempts to extract specified files from a damaged tar file. cpio
cpio is similar to tar in the kind of functionality it provides, cpio is in fact used in the RPM package manager. cpio can work with a number of file formats, including tar.
cpio differs from tar in the following ways: • The file list is passed to cpio on standard input.
• cpio handles a number of different backup formats.
• cpio does not remove leading slashes from file names as tar does (this can be very surprising).
• cpio does not offer tape changing and incremental backups (although you can specify a list of files that is effectively an incremental backup).
• The cpio format stores filesystem information like inode numbers.
cpio o creates an archive on standard output consisting of the files listed on standard input. find /etc | cpio -o -H crc > backup.cpio
find /etc | cpio -o -H ustar > backup.tar
cpio i reads an archive from standard input and creates the files. cpio -i < backup.cpio cpio -i < backup.tar dd dd does a direct dump of data. It is intended for reading a block device, and writing to a block device, or a file. dd is not generally used as a backup tool, because it is likely that the data will change while it is being read, and that the backup will be inconsistent. The syntax for dd is a little different from other command line tools, in that it does not use switches, but named parameters:
dd if=input-file of=output-file bs=block-size count=how-many-blocks
The “input file” defaults to standard input, the output file defaults to standard output14, and the block size defaults to 512 bytes. By default dd will dump as many blocks as are available on the media. To create a backup of a floppy disk, you can do this. dd if=/dev/fd0 of=floppydiskimage bs=18k dd < /dev/fd >floppydisk If you boot a rescue system, dd can clone a partition from a faulty hard drive like this – assuming that the target and destination are the same size.
dd if=/dev/hda1 of=/dev/hdc1 bs=4096k conv=noerror dump
Dump is a fully featured backup tool intended specifically to backup e2fs file systems to tapes (although it is conceivable that it may be implemented for other filesystems).
Dump works with levels 09 where 0 is a baseline back up. Any level greater than 0 is an incremental backup, where all files are backed up that have been modified since the last dump of a lower level. The default dump level is 9. Dump records the time stamp and level of backup in a file called /etc/dumpdate. Dump also looks at the fifth field in /etc/fstab to determine which partitions should be included in a dump.
A typical dump command line:
dump -0uf /dev/st0 /home
14 Some older versions of bash will fail if you attempt to dump more than 2Gbytes of data to standard output or from standard input.
18 Backup strategy LPI 102 Course Notes 115
This will perform a baseline dump on the first SCSI tape of the /home partition. Some useful options to dump include:
B No. of 1k blocks per volume. Useful on tapes that don't correctly report end ofmedia.
F Script to execute when changing tapes.
Restore
Restore is used to extract a dump backup.
restore -xf /dev/st0 /home/student
This will only extract from the dump on /dev/st0 the named home directory. When restoring from a full backup onto a pristine system, the r (rebuild file system) option can be used.