diskutil list # Find out your Raspberry Pi drive
diskutil unmountDisk /dev/disk2 # Unmount disk
sudo dd if=/dev/disk2 of=raspberry_pi_backup.img # Create backup image
gzip -c raspberry_pi_backup.img > raspberry_pi_backup.img.gz # Compress image
gzip -k -d raspberry_pi_backup.img.gz # Uncompress image
diskutil list # Find out your Raspberry Pi drive
diskutil unmountDisk /dev/disk2 # Unmount disk
sudo dd if=raspberry_pi_backup.img of=/dev/disk2 # Restore from backup image. CAUTION: BE SURE TO WRITE TO THE CORRECT DRIVE