Backup SD card

What’s the best way to backup the SD card each week?

I have a Raspberry Pi 2b running OSMC and Kodi but I’ve also added Domoticz, some other scripts, looking to implement NGINX and don’t want to lose it all on an SD card corruption.

I think the OSMC backup only captures settings but is there way to automate a backup to maybe a USB stick in the Pi or perhaps an FTP location on my network to then be able to restore if needed?

Not at this time.
In the future this will be possible

Sounds interesting :slight_smile:

Would rpi-clone work in the mean time?

Never tried it. It would be interesting if you could report back

Need to purchase a new MicroSD card as a backup anyway but will see how it goes.

I assume OSMC is similar to other Raspberry Pi distributions which have a VFAT boot partition 1 and a Linux root partition 2? As this seems to be a requirement.

Yes.

sudo fdisk -l

Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 2048 499711 497664 243M c W95 FAT32 (LBA)
/dev/mmcblk0p2 501760 62521343 62019584 29.6G 83 Linux

So yes as you say :slight_smile:

Now to make Amazon send my SD card and reader quicker :joy:

To backup, I currently just powered off, remove the SD card and take an image of it using my Windows device using Win32DiskImager.

6 Likes

jb2cool> same for me. I tried the dd with gzip but it killed the RPI processor (laggy) and took too long.
At the end this is my safest/easiest way but looking forward an automated solution.

The Pi is used for home automation so having it off is a pain but I guess as a once a month backup it might work.
Still waiting on hardware to try rpi-clone which is just DD and rSync.

Well no luck with rpi-clone, said it worked but when I put the MicroSD card in the Pi doesn’t boot.
Looking at the FAT volume the files are different, the script itself seemed to have errors but the process said it worked.

I tried Win32DiskImager but it took ages and created a file of the same size of the card so then tried Paragon Backup recovery 14 which made an image without all the white space and has restored to back to a backup MicroSD card.

Not ideal as I have to remove the card shut it down etc. but at least I have a starting point now not building from scratch :slight_smile:

BTW looking forward to an automated solution :heart_eyes:

What’s the best way to backup the SD card each week?

Clone the entire card to another of the same size. Use dd or ddrescue for that, but any Linux cloning tool can work. I use something like fsarchiver because it backs up with compression and I don’t have to waste an SD just for a backup. Any tool that does bit-4-bit copies will work, they just waste extra storage. This sort of backup needs to be done off-line - basically remove the SD and connect plug it in elsewhere. Backup at the device level - either whole device or partition. DO NOT MOUNT the storage.

If you don’t need to backup anything except the kodi stuff, you can use any normal linux backup tool like rdiff-backup or rsync or rsnapshot or rbackup and do the backups over a network. I’ve never tried to use a GUI for backups - GUIs and root don’t mix and to get a good backup, the process needs to run as root.

Don’t use FTP. FTP should have died in the mid-1990s. Use something that is secure and respects your credential security. Can’t believe we still have to say that 20 yrs later. Stop using plain FTP. Use sftp instead.

My OSMC has these 2 partitions:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/mmcblk0p2   29G   21G  7.4G  74% /
/dev/mmcblk0p1  240M   21M  219M   9% /boot

That means I need to backup 2 partitions. I don’t keep media on the r-pi, just cached data and metadata. So, on a different machine, I’d run something like these 3 cmds:

sudo sfdisk -d /dev/mmcblk0 /Backups/osmc/log.partitions
sudo ddrescue /dev/sdZ1 /Backups/osmc/osmc-boot-204M.img /tmp/log.osmc.boot 
sudo ddrescue /dev/sdZ2 /Backups/osmc/osmc-data-29G.img /tmp/log.osmc.boot 

sdZ would be the device as seen on a Linux machine. To recreate the partitions for restore on a new disk, there’s an sfdisk import thing - I’d have to look it up. Then I’d reverse the
ddrescue {source} {target} logfile from what was done above.

Clear as mudd? This wouldn’t put the boot sector back - do r-pi’s have that?
Just do a
sudo ddrescue /dev/sdZ /Backups/osmc/osmc-total.img /tmp/log.osmc-total
and everything on the SD will be copied - boot, partitions, data, programs, OS, everything.

FTP over NAT in a controlled environment is completely secure.

Using SFTP will incur significant and unnecessary protocol overhead. On a Raspberry Pi this will make your backups take five times longer for no benefit

Backup from initramfs for best results

1 Like

I back up my Raspberry Pis (I have three, one is running OSMC) and I use Clonezilla. It makes a bit-by-bit copy of all the partitions and copies the partition table and boot sector. It takes about 5 minutes to back up, a little more to restore. Best of all, it works and it’s free.

It may be a little hairy at first for non-technical users but that is the nature of disk structure, booting and partitions. A basic understanding is required, so be prepared to do some Googling and learning. Use the Clonezilla Live version, just take out your Pi SD card, plug it in to your PC and boot from the Clonezilla Live CD, making sure you know exactly which disks are which in your system. Take the options for local disk systems, and work with disks and images (to ensure you copy the entire card, which Clonezilla sees as a disk in its own right).

More information can be found here.

Currently I’m also using the manual process of powering the pis off and backup the hole sd using snapshot Drive Snapshot - Disk Image Backup (on a windows pc).
Doing this since years and for me currently it is ok to power the pi off, maybe once a month or normally before there is and OSMC update, I backup sd and then doing the update :wink:

Such an image is also a good starting point for me, if I maybe want to have OSMC at the next TV station or if I want to test something …

1 Like

There’s a discussion on this here. In my book, copying the files, as is or compressed, is better than making an image with dd or whatever. It takes up less space and allows you to easily compare the backup with the current card if you are troubleshooting. You can also restore to a smaller card if that’s all you’ve got available.

Restoring is arguably more of a faff than with dd but how often do you do that?

Win32DiskImager and compress the file afterward (7zip or else) does the trick too for blank space

I use borg – Borg Documentation — Borg - Deduplicating Archiver 1.2.3 documentation. There is an armhf build here: https://borg.bauerj.eu/.

Enjoy!

1 Like

But there’s only armv5 and armv6 versions. How can I use them on my Pi3?

I need your advice. Which files and directories I must to backup for save my Pi3 full settings?