Raspberry Pi Backup


So, now the “piwall” has been up and running for a while and I’ve done some changes to the config and the system since the last blog post. But what if the Pi decides to eat the SD card or I get hacked or… Oh, I need a backup.

There’s a number of backup solutions to choose among, and I decided to go with an easy one: to clone the whole system – as is – which resides on a 16GB SD card. I tried different ways of doing the cloning and ended up using the command line tool “dd” to accomplish the task.

On a mac, you can use the diskutil program to list the mounted disks:

$ diskutil list
0: FDisk_partition_scheme *15.9 GB disk3
1: DOS_FAT_32 NAMNLOS 15.9 GB disk3s1

In order for dd to work, unmount any partitions on the SD card:

diskutil unmountDisk /dev/diskN

“dd” will perform a block-by-block copy the contents of the SD card into a file. This command will take some time (on my 16GB RAM i7 Mac Book Pro it takes a couple of hours) and there will be no feedback during the process. Adding the “bs” argument may speed up the process.

sudo dd if=/dev/diskN of=/path/to/backup.img bs=1m

Copying the img-file onto a new SD card is a matter of simply reversing the arguments. Just remember to unmount partions as described above on the destination card.

sudo dd of=/dev/diskN if=/path/to/backup.img bs=1m

Update: Using /dev/rdisk instead of /dev/disk may be faster on the mac (source).