0

How to backup my RPI and keep it up to date without needing to create an image with dd. I want to do it from a linux machine via ssh.

With the backup I want to be able

1) to restore the system on the same sd-card

2) to create a new card when the old one is broken

Those instructions did not work for me with a new card.

jake
  • 1,129
  • 7
  • 21
  • When you say you want to create a new card, do you mean connect a blank card to your other machine or restore your old settings to a new Raspbian install over SSH from the other machine? – Roger Jones Jan 08 '19 at 16:20
  • @RogerJones That does not really matter. Important is that it is easy to restore when the sd-card is broken. Also the (old) kernel with compiled drivers should work again. – jake Jan 08 '19 at 16:29
  • If you're happy compiling drivers etc.etc. then getting [Time Shift](https://github.com/teejee2008/timeshift) to run on the Pi might be worth a shot, although also getting it to work over SSH might be asking too much. Combined with an `rsync` backup of your `$HOME` it might be what your'e looking for: new Raspian on card + rsync restore of `$HOME` + TimeShift restore of system from `$HOME`. – Roger Jones Jan 08 '19 at 18:02
  • *did not work* --- why? what happened? – Jaromanda X Jan 08 '19 at 22:14
  • I described it [here](https://raspberrypi.stackexchange.com/questions/92742/restore-backup-failed-using-rsync) as also linked in the question. – jake Jan 09 '19 at 00:49
  • See my answer to your previous backup question, should be of help: [Restore backup failed (using rsync)](https://raspberrypi.stackexchange.com/a/92957/97392) – binki Jan 11 '19 at 22:48

2 Answers2

3

There is an inherent problem with your live backup approach: you need the entire file system to remain stable during the backup process, otherwise there is no way to guarantee that the backup will correctly work afterwards.

One solution is to remount your filesystem read-only during the backup process (pretty much impossible for / on a running system, realistically, you'd have to setup / to be readonly from the start). At which point you might as well use dd and backup the entire image. Another solution is to use LVM or a similar technology that supports snapshots.

Any solution which doesn't freeze the content you're trying to backup may work in some cases, but there will always be an edge case where it will fail. It's not necessarily the problem you're facing now, but I urge you to consider this fundamental issue before you spend more time on this live backup approach.

Dmitry Grigoryev
  • 26,688
  • 4
  • 44
  • 133
1

The instructions you referenced make a copy (of the relevant parts) of the files on the root partition. To make a copy of an OS you ALSO need to copy the files on the boot partition AND the partition table (or be able to re-construct one with the right settings).

Your earlier attempt failed because you only restored part of the image.

In order to restore to the same SD Card it MUST already have the same kernel/firmware - OR you need to have made a copy of the boot files. My restorations have usually been to recover from operator error.

If copying to a new SD Card it needs to be partitioned and formatted FIRST any you need to modify PARTUUID entries in BOTH /etc/fstab and /boot/cmdline.txt to match your SD Card.

The above are not difficult, but there are quite a few steps.

I regularly create SD Card images (to use as security backup) particularly before major updates - although I rarely use the images. See Clone Raspberry Pi SDCard to file on Mac OS X? (this is macOS specific - there are plenty of examples for other OS) On the few occasions when I have to restore this is simple - and I can go back to historic backups if necessary.

I also use rsync to backup files to disk See Can a Raspberry Pi be used to create a backup of itself? These are mainly used to restore specific files. I also use rsync to synchronise SD Card images.

PS SD Cards rarely break. I have only had 3 or 4 corrupted cards with 16 cards and too many Pi over more than 6 years and only a single failure.

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • Now I'm able to start (the PARTUUID was magically right). But there went something wrong with the permissions, so I can't even use `sudo`. (`sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set`). So I think I will use a combination of `dd` and `rsync` in the future. (It seems the issue with the sd-card was a corner, which broke off. I fixed it with some tape...) – jake Jan 09 '19 at 01:15