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:
- Backup (or restore) the partitions using sfdisk
- (Restore only) Create the filesystems on the destination
- 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_zldu0Ra6MEEepTSKCzD55ANeasQO...
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.
Steve