restic-systemd-backup
is a collection of systemd units and shell
scripts that allow me to backup my systems.
The initial idea for the code contained in this repository came from this blog post and this github issue.
This repository mostly is a collection of scripts and systemd units.
The Makefile
provides a convenient way to copy the files
in the repository to the system. However, additional manual work is
required before first use.
Templated systemd units provided by this repository assume that a
directory containing further configuration exists under
$REPO_DIR/etc/restic-systemd-backup/%I/
.
The following prerequisites must be met in order to use
restic-systemd-backup
:
- The
restic
binary must be installed on the system. - A designated backup user must be created. By default this user is
assumed to be called
restic
.
In order to install the files to $REPO_DIR/etc/restic-systemd-backup/
execute the following command:
sudo make install
The REPO_DIR
defaults to /usr/local
. In order to change prefix
execute:
sudo REPO_DIR="/somewhere/else" make install
Filesystem level backups are provided by the
restic-backup-fs@.service
service. In order to schedule regular filesystem level backups execute
the following steps:
- Create a directory
$REPO_DIR/etc/restic-systemd-backup/<instance-name>
. - Create the file
$REPO_DIR/etc/restic-systemd-backup/<instance-name>/restic
setting any environment variables used to configurerestic
. At the very minimum it must setRESTIC_REPOSITORY
andRESTIC_PASSWORD
. The restic documentation describes additional ways to configure restic. Note that if the file containsRESTIC_PASSWORD
it should be readable by therestic
user only. - Create the file
$REPO_DIR/etc/restic-systemd-backup/<instance-name>/files
defining which files and directories restic should backup. The restic documentation for the--files-from
flag explains the format of the file. - Enable and start the
restic-backup-fs@.timer
.
The
restic-backup-forget@.service
allows to automatically remove outdated backups based on a fixed
schedule. Once the filesystem level backups are configured the only
thing left to do is to enable and start the
restic-backup-forget@.timer
.
The [restic-backup-failed@.service
] provides notifications in case one
of the restic-backup-*.service
units fails. In order to enable
notifications for a instance create a directory
$REPO_DIR/etc/restic-with-systemd/<instance-name>/notify.d
and place one
or more executable files into it.
See the notify-failed-*
files in the scripts
directory
for example. Of course one or more of the notify-failed-*
can by
copied or symlinked to the notify.d
directory.
Copyright © 2022 Ferdinand Hofherr
Distributed under the MIT License.