Keeping BackupsKeeping a good set of backup files is one of the primary responsibilities of a system administrator. Even if you're the only person on the system, you still want to have backups! An ideal backup system
There are a number of venerable Unix tools for creating backups that are all designed to preserve the ownership, permissions, and modification dates of files when used by root, and are commonly used in scripts that automate the backup process. The most common of these tools are the tar ( tape archive ) command and the dump and restore commands. The dump command is designed to make backups and includes the ability to make incremental backups. Another frequently overlooked tool is pax so named because it can handle files created by tar and another program, cpio , allowing them to peacefully coexist. One valuable feature of pax : It allows you to specify files to copy based on their modification date. See man pax for details. Unfortunately, dump and restore do not work at all on the Mac OS X standard HFS Plus file-system format. And neither tar nor pax properly handles so-called complex files created by older Mac applications. These files have multiple data streams or forks . (Review the sidebar "Old Mac Files in the Unix World" in Chapter 5.) As of this writing (summer 2005), Apple had no plans to create new versions of the standard Unix backup tools that handle HFS Plus file systems or complex files. Starting with version 10.4 of Mac OS X, the cp command does properly handle these complex files. For an excellent technical discussion of the issues, see "The Challenges of Integrating the Unix and Mac OS Environments" (www.wsanchez.net/papers/USENIX_2000/). So, you cannot use the standard Unix tools to perform standard "full" and "incremental" backups on Mac OS X. You may use the cp command with the -p option to preserve the files' permissions, modification time, and so forth, but even then the related information in the metadata store and content index do not get backed up. Doing full and incremental backups from the command lineThe bad news is that as of Mac OS X 10.4, the standard Mac OS X installation provides no simple way to perform an incremental backup of your entire system from the command line. The good news is that thanks to the open nature of Darwin and the work of people outside Apple, there are tools you can install that will perform incremental backups. See the sidebar "Darwin Backup Tools for HFS Plus." Mac OS X does come with a command-line tool called ditto that you can use to make almost full backups of your system, and to safely back up any subset of your filesfor example, the /Users directory. Incremental backups, though, are something ditto won't do. The ditto command backs up entire directories, preserving (in most cases) all the file attributes, such as permission, ownership, and dates, and handles complex files. Using dittoThe ditto command comes with Mac OS X and properly handles both standard Unix files and older complex files. From the ditto man page: "Ditto copies one or more source directories to a destination directory. If the destination directory does not exist it will be created before the first source directory is copied ." The ditto command preserves the ownership, permissions ("mode"), and modification times of all the files it copies, but will not alter the ownership, mode, or times on any directories that already exist in the destination. Thus, if you change the permissions (or ownership) of a directory you have already copied with ditto , and then copy it again to the same destination, the copy will not pick up the new ownership or mode. That is an important limitationthe only way around it would be to use ditto only to copy to empty destination directories. In the following tasks we assume you have an additional disk for backups, perhaps an external FireWire disk. All disks and volumes besides the boot volume are mounted as subdirectories of /Volumes , so if you had an external FireWire hard drive named "big disk," for example, it would show up in the file system as /Volumes/big_disk (review Figure 5.1 for a schematic diagram of a typical Mac OS X file system). There are subtle differences in how you use ditto when copying directories as opposed to copying individual files. We'll show you directories first.
To back up a directory with ditto:
Tip
Backups are only good if you can use them to recover files. When you are recovering files from backups (which is, essentially , copying them back), you have one of two common situations: Either you want to recover one or more specific files, or you want to recover entire directories. If you want to recover a directory, you can use ditto as described in the task above. If you want to recover specific files, then you need to use ditto in a subtly different way. To use ditto to copy or recover individual files:
|