Make Back Ups from the Command Line in Mac OS X with These 4 Tricks
These days there are no shortage of ways to backup your Macintosh. Probably the most popular method available to an end-user is Apple’s Time Machine which is handled automatically after a simple setup through the GUI, or can be triggered to start at any time. Personally, I was very impressed with the ease of use offered by Time Machine, but I am a command line junkie so I must report on the alternatives available, four of which reside in the very command line of Mac OS X.
Read on for a few different methods that you can use at the Terminal to back up your Mac, using the ditto, rsync, asr, and hdiutil.
sudo ditto -X src_directory dst_directory
Ditto is a built-in part of Mac OS X and ships with all versions. Ditto is fairly robust and can backup your files preserving both ownerships attributes and resource forks. One nifty feature that Ditto offers is it’s ability to “thin” binaries of their PPC or i386 code. For instance, if you own an older PPC Macintosh you can add –arch ppc to your command line options and every binary file that is backed up will be stripped of it’s x86 binary code. This will result in smaller backups.
sudo rsync -xrlptgoEv --progress --delete src_directory dst_directory
Rsync is a versatile and popular method for performing backups not just on the Mac but on Linux and Unix servers across the “IT-globe”. Rsync can do everything you need to perform a reliable backup of your OS X system, including resource forks and preservation of the ability for your hard drive to be “bootable”. An in depth look at rysnc’s abilities can be found here.
sudo asr -source src_directory -target dst_directory -erase -noprompt
asr, or the Apply Software Restore utility is yet another excellent and efficient way to perform a backup. ASR can do everything that Ditto can do plus it has the ability to copy a hard disk at the block level. The block level is the “lowest” possible form to access a hard drive and provides true 100% replication of data. The block level functionality of ASR must be performed on hard disks that are not currently mounted in your operating system. This typically means booting from a recovery disk, usb install or similar.
sudo hdiutil create dst_image.dmg -format UDZO -nocrossdev -srcdir src_directory
If you have ever wanted to create a simple and single file backup of your Macintosh, then hdiutil is for you. Hdiutil performs a backup to a single (optionally compressed) disk image file that can be restored using Apple’s Disk Utility software.