Keeping Backups


Keeping Backups

Keeping 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

  • Makes copies that are easy to recover.

  • Preserves all file attributes, including ownership, permissions, and creation/modification date.

  • Only backs up files that have changed since a particular prior backup. This is called an incremental backup.

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 line

The 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 ditto

The 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.

Darwin Backup Tools for HFS Plus

We are aware of several projects under way to create HFS Pluscompatible command-line tools for performing backups and other file-copying operations.

One such project is psync . The psync utility is a Perl script created by Dan Kogai that will perform incremental backups and restores on an HFS Plus files ystem. You can obtain psync from http://www.dan.co.jp/cases/macosx/psync.html. You may want to refer to Chapter 13, "Installing Software from Source Code." There is also a project called PsyncX that provides a graphical interface (that is, an Aqua interface) to psync . PsyncX is available from (http:// sourceforge .net/projects/psyncx).

Another project is hfstar , a version of the tar command that works properly with the HFS Plus file system and with older Mac files. We have tested hfstar successfully but not extensively. hfstar can be obtained from metaobject (www. metaobject .com/Products.html).

Two other HFS-compatible tools are hfspax and rsyncx . hfspax is intended to replace the pax program that comes with Mac OS X. You can get hfspax from its creator, Howard Oakley (http://homepage.mac.com/howardoakley). The rsyncx utility is available from MacEnterprise.org (www.macosxlabs.org/rsyncx/rsyncx.html).


To back up a directory with ditto:

  • sudo ditto -rsrc source destination

    The -rsrc option (it is one option, not four) tells ditto to preserve the extra data in old-style complex files. This option is the default behavior, but it can be overridden by setting the environment variable DITTONORSRC. Using the -rsrc option ensures that its behavior will be invoked.

  • Enter your password if sudo prompts you for it.

    In this task we assume that source is a directory. You can specify more than one source. The destination must be a directory, not a file.

    ditto will copy the contents of the source directory (or directories) into the destination directory.

    For example, to back up all your users' home directories to an external disk mounted on /Volumes/big_disk :

     ditto -rsrc /Users /Volumes/big_disk/  backups/Users 

    That command line will copy the contents of /Users into /Volumes/big_disk/backups/Users .

    It is very important to note that ditto will not copy the source directory itself, just its contents. So in the example above, ditto does not copy the /Users directory, but instead copies everything inside /Users into

    /Volumes/big_disk/backups/Users

Tip

  • Use the -v option to ditto to have it print out the name of every source directory, or use the -V option to see the name of every file it copies.


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:

  • sudo ditto -rsrc source destination

    If that command-line pattern looks the same as the one in the previous task, you are right, it is the same. The difference here is that if the source is a file (as opposed to a directory), then the destination may be either a file or a directory. If the destination is a directory, then the source file(s) are copied into the directory. If the destination is a file, then it is overwritten. If the destination does not exist, then it is created as a file. For example,

     sudo ditto -rsrc /Volumes/big_disk/  backups/Users/vanilla/Documents/  Contract.doc/Users/vanilla/  Documents/Contract_recovered.doc 

    copies the file Contract.doc from the backup disk to vanilla's Documents folder and calls the copy Contract_recovered.doc.

    As with all uses of sudo , you may be prompted for your password if you haven't used sudo in the last 5 minutes. If you are prompted, enter your password.

Compare with Aqua: Making Backups

The simplest way to make backups in Aqua is to have a second disk drivesuch as an external FireWire driveand simply copy files using the Finder.

Automated backup software for Mac OS X includes the minimalist PocketBackup, from Pocket Software (www.pocketsw.com), or the industry-standard EMC Dantz Retrospect, from EMC Dantz (www.dantz.com).

PocketBackup (as of version 1.0.1) is most useful for backing up files in your own home directory. In order to use it to properly back up files for multiple users and all system files, you would have to log in to Aqua as root, which is generally a bad idea.


Compare with Aqua: Restoring from Backups

Restoring files from backup copies in Aqua can be as simple as copying them from the backup media using the Finder.

Copying files in the Finder works fine for files that are supposed to be owned by the user doing the copying, but it is not a good idea for system files or sets of files belonging to multiple users, because the ownership and permissions on the files will be wrong (the files will end up being owned by the user who performs the copy, and in some cases you won't even have permission to make another copy). In those cases, you should either use the GUI application that created the backups in the first place (such as EMC Dantz Retrospect) or use the command-line ditto program. One good GUI application for making backups in Mac OS X is the shareware Carbon Copy Cloner (CCC), which can make a bootable clone of your boot disk (http://www.bombich.com/software/ccc.html).




Unix for Mac OS X 10. 4 Tiger. Visual QuickPro Guide
Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)
ISBN: 0321246683
EAN: 2147483647
Year: 2004
Pages: 161
Authors: Matisse Enzer

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net