3

I recently setup my RPi so that it boots from a hard drive (as much as I could move off of the SD card anyways). Previously I was simply plugging my RPi SD card into my computer and making a clone with Win32DiskImager, but obviously now I can't do that (or does that method still work?)

I'm planning on buying a new external hard drive for it soon so I'd like to simply copy the whole system to an image rather starting from scratch again. I'd also like to just keep a backup around for emergencies.

SHiLLySiT
  • 33
  • 6
  • I recently used this guide to clone my SD card, it might be of help to you - http://lifehacker.com/how-to-clone-your-raspberry-pi-sd-card-for-super-easy-r-1261113524 – BantuTech Jun 23 '15 at 02:47
  • 1
    As I mentioned in my post, I was following that method until I used [this guide](https://melgrubb.wordpress.com/2014/08/01/raspberry-pi-home-server-part-6-adding-a-hard-drive/) to boot _mostly_ from an external hard drive. I get the impression that I'd only clone what's still on the SD card and not what is now on the external HD. – SHiLLySiT Jun 23 '15 at 02:51

2 Answers2

2

With the system running, you could do this, which does not create a gigantic image of the entire partition but only copies actual data, which can be copied/synced out again.

Another method would be to use tar to archive and compress the contents into a single file. Tar takes an --exclude-from argument exactly like rsync, so you could use it the same way while the system is running. If the partition is < 50% full (so you can temporarily leave a backup there), make a destination directory for it and exclude that with plain --exclude (see below, and man tar).

If you have another linux box, you could also mount the partition there (e.g. /mnt/pi-hd) and then you do not have to worry about excluding the system partitions because they will not exist when the system isn't running. In this case, again assuming there's enough space for the backup on the partition itself, create a place for it and exclude that directory:

cd /mnt/pi-hd
mkdir backup
tar -cjf backup/pi-hd.tb2 . --exclude='backup/*'

The . in the middle refers to the current directory. If there isn't space on the partition itself, just use an external path and leave the --exclude out.

To use this latter, just put it in the right place and unpack it:

tar -xjf pi-hd.tb2

If you want copy that out the partition again, use rsync. It may help to create a temporary directory, copy a few files in, and practice with that to get the hang of how this works.

goldilocks
  • 56,430
  • 17
  • 109
  • 217
1

Once you start booting you Pi from the hard drive, backing it up becomes a lot more like backing up a standard linux PC. From the command line you can use 'dd'

To make backup images of your hard drive-

  1. Get an SD card and burn Raspbian onto it. (You DON'T do this from a mounted partition)
  2. Boot to that SD
  3. plug in and mount the drive where you will store the backup image
  4. plug in but DO NOT MOUNT the drives you wish to back up.
  5. use dd to image your drive (So if your drive is /dev/sda and your backing up to /media/usb/) you'd do something like:

    dd if=/dev/sda conv=sync,noerror bs=64K | gzip -c > /media/usb/sda.img.gz

    1. Then later to restore you'd gunzip and dd:

    gunzip -c /mnt/usb/sda.img.gz | dd of=/dev/sda conv=sync,noerror bs=64K

Hope this helps!

alphacharlie
  • 412
  • 2
  • 5
  • 1
    Don't use `dd` for this unless your keyboard is missing all the other letters. It is NOT a backup tool. It is particularly ridiculous on hard drive partitions, which may be hundreds of gigabytes in size but only 20% full. – goldilocks Jun 23 '15 at 11:01
  • Perhaps, but the poster is talking about buying a new hard drive and cloning his system to it. I've found that dd works well for that. (he could also just use gparted and do it in a GUI...) – alphacharlie Jun 23 '15 at 22:09
  • The OP also mentions "having a backup around"; `dd` "works well" for this in the same sense that having a hammer may "work well" sometimes if you don't own a screwdriver. Is it feasible -- yes. If you almost never have to put in a screw, you might get by with a hammer, but that does not mean it should be recommended to people. There are better and more appropriate tools. Namely screwdrivers. – goldilocks Jun 23 '15 at 22:37
  • The poster said they've got most of their system on the hard drive and they are moving to a larger one. 'dd' is the most reliable way to do that. Even were one to use 'tar' the -p flag would need to be added or one would risk making their system unbootable. – alphacharlie Jun 23 '15 at 22:52