Backup Strategy for Raspberry Pi

I run my Raspberry Pi with a SD card, which are known to die faster than ssd disks. Therefor I’m looking for a backup & restore strategy to backup the whole system. My idea:
Backup:

  1. Shutdown Raspi and clone the sd card on a linux system - i.e. with dd.

  2. Do scheduled backups of the / folder on the Raspi. Exclude
    /dev/*
    /mnt/*
    /proc/*
    /sys/*
    /tmp/*
    /var/log/*
    from backup.
    Here the script I use to do the backups.

Recover:

  1. On the linux system write the full image to the new SD card.

  2. On the linux system recover the latest restic backup to the new SD card.

This seems to work except that I see nearly 20.000 “Symlink: … file exists” errors.

How could I get rid of those?
Does someone have a better strategy to recover a system to get a bootable disk?

Thanks for hints or ideas.

Based on your description of your process, it sounds like you are trying to restore into a directory that already contains the same files as the backup. My understanding is that restic will not restore on top of files that already exist, and it also won’t delete files that do exist. So using the SD card image is exactly what is causing the problem – you aren’t restoring to a clean, empty directory.

Don’t explicitly exclude /dev, /mnt, /proc, or /sys. Just use --one-file-system.

Just back up the partition table and MBR. There’s no reason to back up any of the partitions that you include in the restic backup.

1 Like

Hhm, aren’t there some threads saying that either exclude or --one-file-system would result the same?

Any hints how I should do this?

1 Like

--one-file-system does not need any upkeep to understand not to descend into mounts. Using --exclude requires you to update the script every time your distro makes changes, such as the introduction of new filesystems. E.g., on some systems, /run has been changed to be a tmpfs.

That depends on the disklabel type and several other factors.

1 Like

I use a Raspberry Pi too and my backup solution is almost the same as you and for me it have worked for restoring. I must say, thanks to restic I restored a damaged raspi installation (I was the one who damaged the thing playing around with configurations). So, I make 1 4am snapshot every day and that’s it. I use --exclude instead of --one-file-system and these are my exclusions:

/root/*/.cache
/home/*/.cache
/proc/*
/sys/*
/dev/*
/run/*
/mnt/*
/media/*
/etc/mtab
/var/cache/apt/archives/*.deb
lost+found/*
/tmp/*
/var/tmp/*
/var/backups/*

As I have already said, it worked for me. I try to have most of my configurations in my user’s home because that way, if I need to restore to a new installation I mostly just need to restore my home files but there are always files needed in /etc, for example. My installation is pretty simple, I must say; I just use samba ssh plexmediaserver and I have a couple of custom startups services, cron jobs to manage backups and attached HDD’s that are encrypted. So, when I huged up my installation in the past, I just took my SD and restored damaged directories with restic and that was enough to make my raspi run again. That was about 3 months ago and it is still working like charm.

2 Likes

If you are interested in just cloning your SD card, check out rpi-clone. It can do a live clone of the SD card (while the RPi is running) to another SD card or USB flash drive (which is what I do). I run it weekly in a cron job.

2 Likes