1

I'm trying to make a backup of my raspberry pi (raspbian) so I can come back to this backup just in case something bad happens. The problem is that I only have 1 SD card. I know that you can use SD Card Copier to copy the files to a USB Drive.

I'm wondering if I can copy the files back from the USB Drive onto the SD card. I would be using Ubuntu 16.04 to do the copy back.

Is this possible?

Thanks.

1

As you have discovered using SD Copy to a USB Drive is not a good idea.

While I agree with goldilocks that rsync is a more efficient way of backing up files it is not the ideal way to make a security backup of a SD Card.

rsync requires a properly formatted file system for restoration, and will not backup the /boot sector (although this can be done as a separate step).

I use BOTH rsync and dd to backup my Pi.

I regularly create SD Card images (to use as security backup) particularly before major updates - although I rarely use the images. See Clone Raspberry Pi SDCard to file on Mac OS X? (this is macOS specific - there are plenty of examples for other OS) On the few occasions when I have to restore this is simple - and I can go back to historic backups if necessary.

I also use rsync to backup files to disk See Can a Raspberry Pi be used to create a backup of itself?

This is good for saving files BUT only saves the latest copy - as anyone who has been using computers for some time knows having a single backup is a recipe for disaster.

All of my scripts include sanity checks to prevent inadvertent damage to other partitions etc.

2

From Ubuntu you can create an SD card image this way (this requires superuser privileges, e.g., via sudo):

dd if=/dev/mmcblk0 of=mybackup.img bs=4M status=progress

Beware the dev node (mmcblk0) is not a partition. There will be mmcblk0p1 and mmcblk0p2 partitions, they are not what you want. You want the whole SD card device. It may be listed as something else, e.g., if you use a USB card adaptor it will be something like sdb (and the partitions, sdb1 and sdb2).

To put the image back on a card:

dd if=mybackup.img of=/dev/mmcblk0 bs=4M status=progress

This will destroy whatever was on the card. There is no point in formatting or prepping it first, dd is all that is needed.

A potential problem with this is that the image may be bigger than the new card, for which reason you may want to shrink it:

Reverse the expand root FS 1

As a final comment, using dd or anything else which copies the entire card everytime is the 2nd worse possible way of maintaining a backup, 1st being not doing anything until it is too late. So it's better than nothing, but you may want to consider an alternative, particularly if you need to keep the backup frequently updated.


  1. That post also explains how to create an empty image using fdisk. If you have a copy of the SD card contents from SD card copier, you can create a new card the exact same way, e.g. fdisk /dev/mmcblk0 instead of fdisk test.img. Make the first partition ~60 MB and the second one can just take the rest of the space, then rsync everything back in.

    You should check the backup copy contents first to make sure it did not include any of the stuff mentioned in that post that should not be in a backup (/proc, /dev, etc.).

  • I know this is how the common way to do it. But when I have a 128 GB SD card, this creates a 128 GB .img file. When I use the SD Card Copier, it only copies the files from the boot partition and rootfs partition. I can store all that onto a 8GB USB drive. I don't want to create a full .img, I want to copy the files back. – Test4444 Dec 15 '18 at 21:12
  • Good for you. As I said, copying the whole card using dd or anything else is an atrocious method, but it is common anyway. I'm unfamiliar with SD card copier, but I've added a footnote above that might be of use to you. – goldilocks Dec 15 '18 at 21:26
  • Ahh okay, looks like Rsync is what I want, no .img. thanks. – Test4444 Dec 15 '18 at 21:34
  • For the adventurous you may want to look into Timeshift. It's not available as a ARM binary for the Pi but can be compiled for it, see. – Roger Jones Dec 17 '18 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.