https://github.com/fhofherr/restic-systemd-backup
Collection of systemd units and shell scripts that allow me to backup my systems.
https://github.com/fhofherr/restic-systemd-backup
backup restic restic-backup restic-backups systemd-service systemd-timer
Last synced: 4 months ago
JSON representation
Collection of systemd units and shell scripts that allow me to backup my systems.
- Host: GitHub
- URL: https://github.com/fhofherr/restic-systemd-backup
- Owner: fhofherr
- License: mit
- Created: 2022-11-24T21:09:47.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-02T17:49:45.000Z (about 1 year ago)
- Last Synced: 2025-01-05T09:42:41.230Z (5 months ago)
- Topics: backup, restic, restic-backup, restic-backups, systemd-service, systemd-timer
- Language: Shell
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# restic-systemd-backup
`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](https://tdem.in/post/restic-with-systemd/) and [this
github issue](https://github.com/restic/restic/issues/1015).## Usage
This repository mostly is a collection of scripts and systemd units.
The [`Makefile`](./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/`.### Prerequisites
The following prerequisites must be met in order to use
`restic-systemd-backup`:1. The `restic` binary must be installed on the system.
2. A designated backup user must be created. By default this user is
assumed to be called `restic`.### Installation
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 backups
Filesystem level backups are provided by the
[`[email protected]`](./systemd/[email protected])
service. In order to schedule regular filesystem level backups execute
the following steps:1. Create a directory `$REPO_DIR/etc/restic-systemd-backup/`.
2. Create the file
`$REPO_DIR/etc/restic-systemd-backup//restic` setting any
environment variables used to configure `restic`. At the very minimum
it must set `RESTIC_REPOSITORY` and `RESTIC_PASSWORD`. The [restic
documentation](https://restic.readthedocs.io/en/stable/040_backup.html#environment-variables)
describes additional ways to configure restic. Note that if the file
contains `RESTIC_PASSWORD` it should be readable by the `restic` user
only.
3. Create the file
`$REPO_DIR/etc/restic-systemd-backup//files` defining
which files and directories restic should backup. The [restic
documentation](https://restic.readthedocs.io/en/stable/040_backup.html#including-files)
for the `--files-from` flag explains the format of the file.
4. Enable and start the
[`[email protected]`](./systemd/[email protected]).### Backup removal
The
[`[email protected]`](./systemd/[email protected])
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
[`[email protected]`](./systemd/[email protected]).### Failure notifications
The [`[email protected]`] 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//notify.d` and place one
or more executable files into it.See the `notify-failed-*` files in the [`scripts`](./scripts) directory
for example. Of course one or more of the `notify-failed-*` can by
copied or symlinked to the `notify.d` directory.## License
Copyright © 2022 Ferdinand Hofherr
Distributed under the MIT License.