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.
1) ditto
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.
2) rsync
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.
3) asr
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.
4) hdiutil
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.
Rsync is extremely versatile.
Lbackup is a wrapper to rsync and offers a range of features specifically for Mac OS X systems. With features such as hard linked incremental backup snapshots, highly customizable scripting sub-system, reporting (basic and advanced), as well as a range of bundled example scripts which provide a variety additional features.
Visit the following URL for further details regarding lbackup : http://www.lbackup.org
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.
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.
Thanks for this useful overview!
(esp. the rsync line :-)
To create archived & compressed backups (of mid-sized directories, not the entire system i guess) see:
Combine find & tar to create archives
http://codesnippets.joyent.com/posts/show/1962
Thanks!
Excellent tips for those of us who haven’t upgraded to 10.5.
[…] The rest is here: Command Line Back Ups in OS X Share and Enjoy: […]