Make a backup of a raspberry pi installation remotely using ssh and dd

At work we have a learning and experience centre that have a few exhibitions on display. Some of these are set up using raspberry pi microcomputers. They are actuelly very handy for that purpose, exspecially if you use the two-cell micro sd cards instead of the regular ones. The advantage is that they can run for a much longer time without breaking.

These exhibitions are not always easy to reach, being behind built-in and behind a wall for example. I have set them up so that they start up automatically on power outage, and can be reached over the network.

I still need backups of these installations, and since they are a little inaccessible, but available over ssh, I figured out I could make a backup using dd and ssh.

Running this command let me create a local backup of each of the installations:

$ ssh pi@ip_address "sudo dd if=/dev/mmcblk0 bs=1M" | dd of=backup.img

You can compress the disk image on the fly with this command:

$ ssh pi@ip_address "sudo dd if=/dev/mmcblk0 bs=1M | gzip -" | dd of=backup.gz

The command take some time to complete, so be patient. The result is that I can write out the image to a spare sd card, just in case something happens.

Caution: The backup method might be convenient, but not 100% safe. The backup image can end up not being reliable or even broken. If the backups are crucial, you should back up the micro sd card while not in use instread.