4

*Disclaimer: I can follow directions for Terminal, but I am not a nix user by default.

I have a Raspberry Pi that I just had to restore. Before I get anything else installed I would like to create a clone image that I can restore if required.

I have done this by inserting the SD card in my Mac and using the following:

sudo dd if=/dev/rdiskx of=/path/to/image bs=1m

If I SSH from my Mac, can I create a clone across the network to my machine? There is not enough room on the SD card to do it locally.

Steve Robillard
  • 34,988
  • 18
  • 106
  • 110
Kray
  • 63
  • 1
  • 1
  • 4

3 Answers3

5

it's possible to run ssh to issue a command on the remote end and catch the output on your local machine, something along the lines of

ssh user@192.168.xxx.xx 'dd if=/dev/mmcblk0 bs=10M' | cat > sd_image.img

but actually it's not recommended to read SD card while the system is running from the same SD, because it's very easy to get an inconsistent file system image and you'd much better off using SD card reader on your Mac for creating images with the command you shown above.

lenik
  • 11,533
  • 2
  • 32
  • 37
3

Have a look at my instructions here for using rsync to maintain a backup; at the end there is a brief paragraph about using it via ssh.

If you pay heed the part about what should go in the rsync-exclude.txt list, you can do this while the pi is running. You can also use -e in place of the --rsh I use in the other example, or if you have no special options you need for ssh, just omit it; rsync will use it by default when it sees a network address. So:

rsync -aEv --delete --exclude-from=/rsync-exclude.txt root@yourpi.ip:/ /backup/path

Updates the backup. Using it to restore is explained in the other answer.

goldilocks
  • 60,325
  • 17
  • 117
  • 234
1

The problem with a dd-created image is: you can only write it back to a mSD card that is larger than the image. So if your image is 16GB, trying to write the image onto another 16GB card may chop off some sectors, because the new card has a few sectors less than the old card from which the image was taken. Trying to write an "oversized" image to some USB sticks or mSDs may brick them, as I found out the hard way.

TheDiveO
  • 1,591
  • 1
  • 11
  • 16