[ALUG] RPi SD backup/restore

steve-ALUG at hst.me.uk steve-ALUG at hst.me.uk
Tue Sep 19 17:58:28 BST 2017

On 13/09/17 10:42, Mark Rogers wrote:
> I've been experimenting with backing up and restoring Raspberry Pi SD cards.
> There is of-course a very easy way: use "dd" or similar to create a
> disk image. However it has three disdvantages; it is slow, and it
> creates very large backups. And it's hard to extract individual files
> from the backups.
> I've written up a quick process [1] for doing it manually, which is essentially:
> 1. Backup (or restore) the partitions using sfdisk
> 2. (Restore only) Create the filesystems on the destination
> 3. Backup (or restore) the files using tar.
> However I'd like some advice on scripting and improving it.
> In particular, this process creates three files (one for the partition
> info, and one each for the files from the two partitions). I'd like to
> end up with a single file, which I can do by just tar'ing the three at
> the end, but given the size of the files I want to keep the use of
> temporary files to a minimum.
> Also, at the moment it's quite inflexible in terms of restoring to a
> different sized card, but ought not be.
> But regardless, I figured there'd be enough Pi users around here who
> might find it useful.
> (Use at your own risk, it's had very limited testing so far.)
> [1] https://docs.google.com/document/d/e/2PACX-1vRk_zldu0Ra6MEEepTSKCzD55ANeasQOY9iJFY3Kh9-N_rz7Wdww1NA5CnM0s62i0f1OEyIDD4iFzZz/pub
Could you not just use the built-in sd-card backup/cloning utility?
If you don't want to back-up to a separate sd card or USB stick, you 
could use a mock drive (I think you create a fixed-size file, then 
format it, then mount it) and backup to that.
Alternatively, grab the source for the new sd-card backup utility and 
bodge it to backup to where you want it to.

Re your backup utility, can I ask a stupid question?  If backing up a 
windows filesystem, in order to create a faithful bootable backup, 
certain files have to be in certain locations.  Is the same true with a 
PI-backup.  If so, would one of your backups be restorable to create a 
bootable system?  If not, is there any point in backing up the sfdisk 
stuff?  More fundamentally, if not, just back up the files with tar, 
gzip, zip or other.

For what it's worth, I occasionally backup using DD to an image file, 
which I then zip to save space.  I also have a daily Backuppc backup.  
Backuppc is a pig to set up, but, when it works, it works well.  It has 
the advantage (and possible pitfall), that it backs up only one copy of 
a file - so if you have 2 Pis and 2 linux machines, and they all have 
the same version of a library file installed, only one copy will be 
saved.  This saves tons of space.  The disadvantage of course is that if 
that copy of the file gets corrupted, then all the copies will be corrupted.


More information about the main mailing list