Professional Documents
Culture Documents
Maintain An Effective Data Backup Strategy - LPIC Topic 1.111.5
Maintain An Effective Data Backup Strategy - LPIC Topic 1.111.5
1 Backup strategy
“He who does not plan for failure, plans to fail....”
– Itold Yaso1
1 Bu’tcha dinnae wanna listen
Chapter 1 Backup strategy 2
What to backup
There are a number of approaches to deciding what to backup. Simplistically speaking, you need to
backup anything that can change after installation and that contains information that you need.
Whether or not you need to backup the entire system as is (a full backup) or just the data that
changed since installation (partial backup), would depend upon the difficulty and time involved in:
reinstalling, applying any patches needed and loading all incremental and/or all partial backups.
It boils down to a cost vs risk debate:
1. Calculate how the long will it take to reinstall using each method.
2. Calculate the cost of reinstallation considering labour and downtime costs.
3. Compare this to the cost of the backup technique over the mean time to failure.
Here we go:
Monthly baseline + Full backup every
incremental backups time
1. Time to reinstall – based on number of tapes 1 hour setup, 3 tapes at 1 hour setup, 1 tape at
that must be read, plus some initial time. 2 hours each 2 hours
7 hours 3 hours
2. Cost of reinstallation. Labour at R500 per 7 * R5500.00 3 * R5500.00
hour, lost production at R5000 per hour. R38500.00 R16500.00
3. Cost of backups during this time.
Number of tapes per month 3 tapes 10 tapes
Number of months 120 months 120 months
Cost of tapes R100.00 per tape R100.00 per tape
Total cost over period R36 000.00 R120 000.00
In this case, it is preferable to make a baseline backup and incremental backups, as the cost of the
media far outweighs the benefit of being able to recover from failure faster. Factoring in the reuse
of tapes is left as an exercise to the reader.
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.
2 What do you think happens if you run the command tar czf tarfile.tar.gz? What is included in the archive?
Chapter 1 Backup strategy 4
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.
Chapter 1 Backup strategy 5
• 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 output3, 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
This will perform a baseline dump on the first SCSI tape of the /home partition.
3 Some older versions of bash will fail if you attempt to dump more than 2Gbytes of data to standard output or from
standard input.
Chapter 1 Backup strategy 6
Some useful options to dump include:
B No. of 1k blocks per volume. Useful on tapes that don't correctly report endof
media.
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.
Amanda
The Advanced Maryland Automatic Network Disk Archiver is a sophisticated backup management
tool. Amanda is free software and makes use of the dump command to perform the actual backups.
Arkeia
Arkeia is a commercial backup solution from Knox software. Arkeia has a pleasant easy to use
Java client to manage the server which actually performs the tapebackups. Arkeia is designed to
work with tapes in a large system environment.
mkcdrec
This tool creates a complete image of your filesystem onto CDs. This is useful for a full backup,
especially if it can be contained on a single CD. The image that mkcdrec creates is a bootable
system that can reinstall the system as it was.
badblocks
badblocks finds bad (unreliable) blocks on a specified partition. It is normally used like this:
badblocks /dev/sda3 > badblocklist
The “badblocklist” file is then passed to an appropriate filesystem tool (e.g. mkfs). Usually,
however, badblocks is not run directly, but is invoked with the correct block size by the c option
Chapter 1 Backup strategy 7
to fsck.
disk is needed. This disk will boot up a minimal file system with the root partition being a RAM
disk. You will then be able to perform whatever maintenance tasks are needed on the file system, if
it is still there.
Most distributions have a rescue disk image available on the installation media.
1.2 Review
Quiz questions
1. What are the differences between cpio, dd, dump/restore and tar?
2. What is the syntax for the dd command?
3. Under what circumstance should you use cpio in preference to tar?
4. Which files configure the behaviour of dump?
5. Which commands are capable of backing up a filesystem to tape.
6. What will the following command do?
tar cjvf file /
Assignment
Make a minimal backup of your system. Test whether this backup works by wiping your system
clean and then restoring from the backup. Is your backup practical? How can it be improved?
compare the number of letters in each command (2 for dd, 3 for tar, 4 for cpio and dump and 7
for restore).
2. dd if=inputfile of=outputfile (and more)
3. You would use cpio to read a cpio archive (duh). cpio has a copypass function that you may
like to use for copying. For certain types of media errors, cpio can be more robust.
4. /etc/fstab (and /etc/dumpdate, to a small extent)
5. tar, cpio, dd, dump
6. Create a bzip2 compressed tar archive named './file' containing all files in the filesystem
(including /proc). It will print file names as it proceeds.