Command line Backup/Cloning/Imaging for OSX

Okay so where do we start……yeah good old cpio and tar might be good enough for the true old timers who still back up to tape, but a lot of people these days backup to live Online/Nearline media such as disks. Here is a quick (and platform specific) reference to four backup commands that you should always carry in your back pocket when backing up OSX machines.

  1. Ditto is a command line util that comes with OSX. It’s a neat little application since it can preserve permissions, resource forks and extended attributes of OSX files when run as root. There are several ways of running ditto, but if you just want to clone your system using ditto here is the command:sudo ditto -X / /Volumes/Backup
  2. Rsync is the grand daddy of file syncing/backup utils out there and it comes with OSX as well. You can also use rsync to create a bootable clone of your system. sudo rsync -xrlptgoEv --progress --delete / /Volumes/BackupIn addition to basic copying, rsync can also sync the remote and local targets — ie: if a file gets deleted on the source it gets deleted on remote as well. In this mode rsync only copies files that have changed on the source, so after the initial backup, all subsequent “sync” operations will run very fast. In the above command the -E option is special for OSX, it tells rsync to copy extended attributes for the files being copied.
  3. Next is hdutil which allows you to create a image of your drive in a single file. Although the image is not bootable, it has the advantage of being contained in a nice/neat file. Here is the command to create a compressed disk image of your drive:sudo hdiutil create /Volumes/Backup/mymachinesimage.dmg -format UDZO -nocrossdev -srcdir /
  4. Last but not least is asr, the drive cloning util. This one works similar to ditto in creating a bootable clone of your drive, but it does this in block mode. Every block in the source drive is copied 1-to-1 to the destination drive. To clone your drive using asr use the following command:sudo asr -source / -target /Volumes/Backup -erase -noprompt Note that since your using asr in block copy mode you need to be able to unmount both the source and destination drives. So you can’t really use this command to clone your boot partition/volume. You can boot from a OSX DVD/CD and use this command from the command line.

That’s it…..Have fun backing-up……and do it often :-).

Leave a Reply