Skip to content

fhofherr/restic-systemd-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 and this github issue.

Usage

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/.

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] service. In order to schedule regular filesystem level backups execute the following steps:

  1. Create a directory $REPO_DIR/etc/restic-systemd-backup/<instance-name>.
  2. Create the file $REPO_DIR/etc/restic-systemd-backup/<instance-name>/restic setting any environment variables used to configure restic. At the very minimum it must set RESTIC_REPOSITORY and RESTIC_PASSWORD. The restic documentation 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/<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.
  4. Enable and start the [email protected].

Backup removal

The [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].

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/<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.

License

Copyright © 2022 Ferdinand Hofherr

Distributed under the MIT License.

About

Collection of systemd units and shell scripts that allow me to backup my systems.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published