This tutorial will produce a full backup of your Raspberry Pi SD card. SD cards are oftentimes prone to errors, e.g. when a Raspberry Pi is not shut down gracefully, by pulling the power plug. If you end up with a corrupt SD card on your Pi, you can easily transfer the latest full backup and continue from here.
Package:
sudo dd bs=1M if=/dev/mmcblk0 of=<path_to_externalHD_or_nas>/raspberry_backup.img
Restore:
Remember to choose the correct disk by putting a letter or number in the <sdX> or on Mac <rdiskX> an example could be: of=/dev/sdc
sudo dd if=raspberry_backup.img of=/dev/<sdX>
/dev/sdX must be your SD card, on a Mac it’s /dev/rdiskX