Backup
Connect via ssh
ssh user@hostEnter the password when prompted.
Shutdown
sudo shutdown nowInsert sd card into computer
Remove the sd card from the Raspberry Pi once it has powered off. Then insert it into your computer.
These instructions work for macOS only.
Find device name of mounted sd card
diskutil listLook for a device that matches the size of your sd card. The device probably has a partition called boot.
The device will be called something like /dev/disk2.
Make backup
sudo dd if=/dev/disk2 of=~/Desktop/backup.dmgIncluding useful information like the current date or content of the backup in the filename might be a good idea.
This command can take some time and will not indicate any progress - just hang on.
Eject sd card
sudo diskutil eject /dev/disk2Restore
Insert sd card and identify device name
Find device name as described here.
Unmount sd card
diskutil unmountDisk /dev/disk2Restore backup
sudo dd if=~/Desktop/backup.dmg of=/dev/disk2This command can take some time and will not indicate any progress - just hang on.
Eject sd card
sudo diskutil eject /dev/disk2