An enormous number of open source and proprietary backup utilities is available. Each has its own positive and negative points. Table 9-3 highlights some of these areas. It is important to test each utility and pick the one that best suits your needs.
tartar is very easy to use and is the most common utility for moving and distributing files and directories to other computers. It is less useful as a system-level backup command, though. It can only create files of limited size, it has limited capability for incremental backups (using mtime only), and it lacks integrated capability to use the find command in the way that cpio does. tar is also very unforgiving of media errors. tar must also search an entire volume to find a file to recover, so it is bad for very large archives. Examples of compressing, listing, and extracting a tar archive follow. In the following example, we compress files into a tar archive. The cvzf switches denote create archive (c), verbose output (v), compress the output file (z), and specified device file (f): # tar cvzf /dev/st0 /work tar: Removing leading '/' from member names /work/ /work/lost+found/ /work/vmware/ /work/vmware/state/ /work/vmware/installer.sh /work/vmware/config /work/vmware/locations /work/vmware/vmnet1/ /work/vmware/vmnet1/dhcpd/ /work/vmware/vmnet1/dhcpd/dhcpd.conf /work/vmware/vmnet1/dhcpd/dhcpd.leases~ /work/vmware/vmnet1/dhcpd/dhcpd.leases /work/vmware/vmnet8/ /work/vmware/vmnet8/nat/ /work/vmware/vmnet8/nat/nat.conf /work/vmware/vmnet8/dhcpd/ /work/vmware/vmnet8/dhcpd/dhcpd.conf /work/vmware/vmnet8/dhcpd/dhcpd.leases~ /work/vmware/vmnet8/dhcpd/dhcpd.leases In the following example, we list files in a tar archive. The tvzf switches denote list archive (t), verbose output (v), compress the output file (z), and specified device file (f): # tar tvzf /dev/st0 drwxr-xr-x root/root 0 2005-11-19 14:36:23 work/ drwx------ root/root 0 2005-11-19 14:35:51 work/lost+found/ drwxr-xr-x root/root 0 2005-11-19 14:36:23 work/vmware/ drwxr-xr-x root/root 0 2005-11-19 14:36:23 work/vmware/state/ -r-xr-xr-x root/root 36011 2005-11-19 14:36:23 \ work/vmware/installer.sh -rw-r--r-- root/root 264 2005-11-19 14:36:23 work/vmware/config -rw-r--r-- root/root 4987 2005-11-19 14:36:23 work/vmware/locations drwxr-xr-x root/root 0 2005-11-19 14:36:23 work/vmware/vmnet1/ drwxr-xr-x root/root 0 2005-11-19 14:36:23 \ work/vmware/vmnet1/dhcpd/ -r--r--r-- root/root 743 2005-11-19 14:36:23 \ work/vmware/vmnet1/dhcpd/dhcpd.conf -rw-r--r-- root/root 0 2005-11-19 14:36:23 \ work/vmware/vmnet1/dhcpd/dhcpd.leases~ -rw-r--r-- root/root 417 2005-11-19 14:36:23 \ work/vmware/vmnet1/dhcpd/dhcpd.leases drwxr-xr-x root/root 0 2005-11-19 14:36:23 work/vmware/vmnet8/ drwxr-xr-x root/root 0 2005-11-19 14:36:23 \ work/vmware/vmnet8/nat/ -r--r--r-- root/root 1251 2005-11-19 14:36:23 \ work/vmware/vmnet8/nat/nat.conf drwxr-xr-x root/root 0 2005-11-19 14:36:23 \ work/vmware/vmnet8/dhcpd/ -r--r--r-- root/root 771 2005-11-19 14:36:23 \ work/vmware/vmnet8/dhcpd/dhcpd.conf -rw-r--r-- root/root 0 2005-11-19 14:36:23 \ work/vmware/vmnet8/dhcpd/dhcpd.leases~ -rw-r--r-- root/root 417 2005-11-19 14:36:23 \ work/vmware/vmnet8/dhcpd/dhcpd.leases In the following example, we extract files from a tar archive. The tvzf switches denote extract archive (x), verbose output (v), compress the output file (z), and specified device file (f): # rm /work/vmware/installer.sh # tar xvzf /dev/st0 work/vmware/installer.sh work/vmware/installer.sh # ll /work/vmware/installer.sh -r-xr-xr-x 1 root root 36K 2005-11-20 10:53 /work/vmware/installer.sh cpiocpio is the most versatile backup command. cpio is more complicated to use, but it offers a high degree of flexibility. cpio does a great job of handling media errors and tries to skip bad spots on restore. cpio reads and writes files and directories to be backed up through stdin and stdout, which gives you incredible flexibility. Typically, you pipe find commands through cpio, but you can also run find with the -cpio option to direct the output to cpio. cpio also easily spans multiple tapes. You must use custom scripting to create incremental backups with cpio because the command doesn't have built-in support for backups. However, this scripting can be done without too much pain. cpio also forces the user to read the entire tape to find a file, so it might be less useful for larger backups. An example of cpio in action follows: # find find /work -print |cpio -ovH newc >/dev/st0 /work /work/lost+found /work/vmware /work/vmware/state /work/vmware/installer.sh /work/vmware/config /work/vmware/locations /work/vmware/vmnet1 /work/vmware/vmnet1/dhcpd /work/vmware/vmnet1/dhcpd/dhcpd.conf /work/vmware/vmnet1/dhcpd/dhcpd.leases~ /work/vmware/vmnet1/dhcpd/dhcpd.leases /work/vmware/vmnet8 /work/vmware/vmnet8/nat /work/vmware/vmnet8/nat/nat.conf /work/vmware/vmnet8/dhcpd /work/vmware/vmnet8/dhcpd/dhcpd.conf /work/vmware/vmnet8/dhcpd/dhcpd.leases~ /work/vmware/vmnet8/dhcpd/dhcpd.leases # cpio -itv < /dev/st0 drwxr-xr-x 4 root root 0 Nov 19 14:36 /work drwx------ 2 root root 0 Nov 19 14:35 /work/lost+found drwxr-xr-x 5 root root 0 Nov 19 14:36 /work/vmware drwxr-xr-x 2 root root 0 Nov 19 14:36 /work/vmware/state -r-xr-xr-x 1 root root 36011 Nov 19 14:36 \ /work/vmware/installer.sh -rw-r--r-- 1 root root 264 Nov 19 14:36 \ /work/vmware/config -rw-r--r-- 1 root root 4987 Nov 19 14:36 \ /work/vmware/locations drwxr-xr-x 3 root root 0 Nov 19 14:36 \ /work/vmware/vmnet1 drwxr-xr-x 2 root root 0 Nov 19 14:36 \ /work/vmware/vmnet1/dhcpd -r--r--r-- 1 root root 743 Nov 19 14:36 \ /work/vmware/vmnet1/dhcpd/dhcpd.conf -rw-r--r-- 1 root root 0 Nov 19 14:36 \ /work/vmware/vmnet1/dhcpd/dhcpd.leases~ -rw-r--r-- 1 root root 417 Nov 19 14:36 \ /work/vmware/vmnet1/dhcpd/dhcpd.leases drwxr-xr-x 4 root root 0 Nov 19 14:36 \ /work/vmware/vmnet8 drwxr-xr-x 2 root root 0 Nov 19 14:36 \ /work/vmware/vmnet8/nat -r--r--r-- 1 root root 1251 Nov 19 14:36 \ /work/vmware/vmnet8/nat/nat.conf drwxr-xr-x 2 root root 0 Nov 19 14:36 \ /work/vmware/vmnet8/dhcpd -r--r--r-- 1 root root 771 Nov 19 14:36 \ /work/vmware/vmnet8/dhcpd/dhcpd.conf -rw-r--r-- 1 root root 0 Nov 19 14:36 \ /work/vmware/vmnet8/dhcpd/dhcpd.leases~ -rw-r--r-- 1 root root 417 Nov 19 14:36 \ /work/vmware/vmnet8/dhcpd/dhcpd.leases 94 blocks The following is an example of removing and restoring a file with cpio: # rm /work/vmware/installer.sh # cpio -i "*installer.sh" < /tmp/foo3.out 94 blocks # ll /work/vmware/installer.sh -r-xr-xr-x 1 root root 36K 2005-11-20 10:53 /work/vmware/installer.sh A common mistake with cpio is illustrated next: # find -print /etc/hosts |cpio ov > /tmp/foo2.out find: paths must precede expression Usage: find [-H] [-L] [-P] [path...] [expression] 0 blocks find /etc/hosts -print |cpio -ov >/tmp/foo2.out /etc/hosts 2 blocks # find /etc/hosts -print |cpio -ov /tmp/foo2.out Usage: cpio {-o |--create} [-0acvABLV] [-C bytes] [-H format] [-M message] [-O [[user@]host:]archive] [-F [[user@]host:]archive] [--file=[[user@]host:]archive] [--format=format] [--message=message] [--null] [--reset-access-time] [--verbose] [--dot] [--append][--block- size=blocks] [--dereference] [--io-size=bytes] [--quiet][--force-local] [--rsh-command=command] [--help] [--version] < name-list [> archive] dump and Restoredump only backs up a whole filesystem, so it is not a good choice for backing up just a few files or directories. dump supports up to nine levels of backups. It can restore files, directories, or the entire filesystem. dump does not produce a live index while backing up, but it has very easy interactive recovery capabilities. It is less easily recovered on other versions of UNIX than cpio and tar because it is more closely tied to the source filesystem type of an archive. dump also has a much more complicated archive layout than cpio or tar. cpio and tar treat a backup not as a whole archive but rather as strings of file and directory records. dump writes a table of contents at the beginning of the archive, which is why recovery is faster with dump. This is also why you can use the interactive shell (including ls and cd) with dump. # /sbin/dump -0uf /tmp/foo4.out /work DUMP: WARNING: no file '/etc/dumpdates', making an empty one DUMP: Date of this level 0 dump: Sat Nov 19 14:37:02 2005 DUMP: Dumping /dev/mapper/vg00-test (/work) to /tmp/foo4.out DUMP: Label: none DUMP: Writing 10 Kilobyte records DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 89 blocks. DUMP: Volume 1 started with block 1 at: Sat Nov 19 14:37:02 2005 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: Closing /tmp/foo4.out DUMP: Volume 1 completed at: Sat Nov 19 14:37:02 2005 DUMP: Volume 1 90 blocks (0.09MB) DUMP: 90 blocks (0.09MB) on 1 volume(s) DUMP: finished in less than a second DUMP: Date of this level 0 dump: Sat Nov 19 14:37:02 2005 DUMP: Date this dump completed: Sat Nov 19 14:37:02 2005 DUMP: Average transfer rate: 0 kB/s DUMP: DUMP IS DONE dddd is not a backup command per se, but it can be used to copy a raw device to tape or to a file. It is not flexible at all, and the only way to restore is to perform a full restore. An example of backing up a device with dd is: dd if=/dev/hda1 of=/dev/st0 bs=10k To recover this data, you reverse the command and write from the tape drive to the disk device, which overwrites any contents. dd if=/dev/st0 of=/dev/hda1 bs=10k As you can see, dd is not the most flexible utility. It is commonly used either to back up raw data partitions for databases or to clone an entire disk. mkisofsmkisofs creates an ISO file, which is in CD/DVD format. This file can then be written to CD/DVD. mkisofs is usually paired with cdrecord to write the ISO file to CD/DVD. One option is to turn the files or directories directly into an ISO and burn it to CD/DVD. # mkisofs -o home_backup.iso -JRVv /home/ # cdrecord -v -eject -multi speed=8 dev=0,1,0 home_backup.iso Another possibility is to use tar to zip up the files or directories first and then make them into an ISO and burn them to CD/DVD. # tar -cvzWf /tmp/home_backup.tar.gz /home/ # mkisofs -o home_backup.iso -JrVv /m_backup.tar.gz # cdrecord -v -eject -multi speed=8 dev=0,1,0 home_backup.iso rsyncrsync is an incredible command. It is typically used to synchronize two directories. The rsync man page states: DESCRIPTION rsync is a program that behaves in much the same way that rcp does, but has many more options and uses the rsync remote-update protocol to greatly speed up file transfers when the destination file already exists. The rsync remote-update protocol allows rsync to transfer just the differences between two sets of files across the network link, using an efficient checksum-search algorithm described in the technical report that accompanies this package. Some of the additional features of rsync are: o support for copying links, devices, owners, groups and permissions o exclude and exclude-from options similar to GNU tar o a CVS exclude mode for ignoring the same files that CVS would ignore o can use any transparent remote shell, including rsh or ssh o does not require root privileges o pipelining of file transfers to minimize latency costs o support for anonymous or authenticated rsync servers (ideal for mirroring) rsync is typically used to mirror data between two servers. Here are two examples:
|