How to backup an infrequently powered on Linux desktop PC

I have recently done some maintenance on my mother’s PC which runs Ubuntu Linux. It had stopped working, but luckily it was a dead motherboard and the hard drive was OK, so her important files where not lost. (There was no backup).

Question is, how to schedule backups given that this PC gets turned off when it is not in use? I am thinking it might be possible to schedule a script that will start a few minutes after boot, and then hope that the backup finishes before the PC gets turned off.

I have found an article on stack overflow about how to create an upstart job that runs on boot, but I don’t fully understand the details, or how to make it wait for several minutes before it runs. I am also worried about how to make it robust enough to survive if my mum cuts the power before the backup completes.

Can anyone offer some advice or tips? Apart from being reliable, the most important thing is that it must run unattended without intervention, and be self healing. Anything that relies on me or my mum to remember to run the backup, or unlock the repo will likely get forgotten.

The answer can depend on what init system you’re using. For example, if using systemd there is a way to cause services to start during shutdown. If you do that, gracefully shutting down the system will take a backup first.

You could also schedule a backup to run every hour, for example.

There are multiple ways to schedule backups. One simple way is to use anacron. It basically works like cron, but doesn’t assume that the machine is running non-stop and executes a cronjob at reboot if necessary.

Either use anacron’s build in delay or use a sleep timer in combination with your backup (which works for basically everything):
sleep 180 && restic backup

If the machine is shut down during a backup 2 things will happen:

  • A lock is left behind. This doesn’t matter as along as you don’t execute any commands which require an exclusive lock (e.g. forget and prune). You’d need to run restic unlock prior to those commands.
  • Files (or blobs) are uploaded to the repository and index files referencing those blobs are saved every 15min. But no snapshot is created until the backup is complete. If you need to restore any of the files not contained in a snapshot you will have to use restic recover. This command is implemented by PR #2056 but has not made it into a release yet.

Thanks @764287

anacron did the trick. It was easy to configure it to run the backup, and thanks for the re-assurance that the backup will still be good if sometimes gets interrupted by a shutdown while it is running.

Is it possible that nobody noticed this? Your mom is totally hardcore. Mine cannot figure out her iPad.

Please tell me that her primary application for this PC is authoring tex documents using emacs .

2 Likes

Thanks. My mum is not that hardcore, she just uses the PC that I setup for her, and I chose Ubuntu because I could ssh into it for remote support, and because the PC came from a small local vendor who offered a substantial discount for hardware without an OS installed.

I think my mum mostly writes stuff in Libre Office. I am fairly sure she would have no idea how to use a bash command line.

1 Like

If your mom has a specific directory for her user files then those can be put in a separate backup. So there would be a larger but complete system backup and a smaller but runs much quicker backup of only here files. That is do you need to check the os to see if it needs a backup. Many casual users only change a few files so a backup of user only files might be very quick.