Backup and restore a Raspberry Pi SD card

This topic has been discussed numerous places throughout the Internet, but I always find myself having to re-google this every time I need it. For my own reference, the steps to backup an SD card on OS X are:

  1. Insert the SD card into your Mac (seems obvious)
  2. From terminal, run `df -h` and make note of your SD card. My shows up as "/dev/disk2s1"
  3. Launch Disk Utility, and "unmount" that partion. (Note: do not eject it).
  4. From terminal, run dd to backup. If the partion noted in df was "disk2s1" we'll be backing up "disk2". For example: "sudo dd if=/dev/disk2s1 of=my-backup.img bs=1m"

That is it for backing up. To restore an SD card from backup:

  1. Insert the target SD card into your Mac (again, obvious, right?)
  2. From terminal we'll run `df -h` again to verify the correct device. Though unlikey to have changed from the restore step, it's always good to double check this. A mistake here will result in you toasting something.
  3. From Disk Utility "unmount" the partion noted in step 2. (again, do not eject it)
  4. From terminal we'll run dd to restore our SD card from backup. If the partiion noted in step 2 was "disk2s1" we'll be restoring to "disk2". For example:

When storing a backup image long term (e.g., for anything longer than simply backing up to immedately restore to a new SD card), I compress my backup files.

To compress, simply:

To decompress:

That should be it, have fun!