Multiple profile configuration (#45)

Adds possibility to have multiple profiles with different backup paths, retention etc.

Co-authored-by: Matt Feifarek <matt.feifarek@gmail.com>
Co-authored-by: Erik Westrup <erik.westrup@gmail.com>
This commit is contained in:
Gerard Bosch
2022-02-01 10:09:36 +01:00
committed by GitHub
parent 16dbe699ab
commit d8f25cdf88
16 changed files with 221 additions and 105 deletions
+20
View File
@@ -0,0 +1,20 @@
# Global envionment variables
# These variables are sourced FIRST, and any values inside of *.env files for
# specific configurations will override if also defined there.
# Official instructions on how to setup the restic variables for Backblaze B2 can be found at
# https://restic.readthedocs.io/en/latest/030_preparing_a_new_repo.html#backblaze-b2
# The restic repository encryption key
export RESTIC_PASSWORD_FILE="/etc/restic/pw.txt"
# The global restic exclude file
export RESTIC_BACKUP_EXCLUDE_FILE="/etc/restic/backup_exclude"
# Backblaze B2 credentials
export B2_ACCOUNT_ID="<b2-account-id>" # TODO fill with your account info
export B2_ACCOUNT_KEY="<b2-account-key>" # TODO fill with your account info
# How many network connections to set up to B2. Default is 5.
export B2_CONNECTIONS=10
-8
View File
@@ -1,8 +0,0 @@
# B2 credentials.
# Extracted settings so both systemd timers and user can just source this when want to work on my B2 backup.
# See https://restic.readthedocs.io/en/latest/030_preparing_a_new_repo.html
export RESTIC_REPOSITORY="b2:<b2-repo-name>"
export RESTIC_PASSWORD_FILE="/etc/restic/b2_pw.txt"
export B2_ACCOUNT_ID="<b2-account-id>"
export B2_ACCOUNT_KEY="<b2-account-key>"
-1
View File
@@ -1 +0,0 @@
<b2-password>
+34
View File
@@ -0,0 +1,34 @@
# This is the default profile. Fill it with your desired configuration.
# Additionally, you can create and use more profiles by copying this file.
# This file (and other .env files) has two purposes:
# - being sourced by systemd timers to setup the backup before running restic_backup.sh
# - being sourced in a user's shell to work directly with restic commands e.g.
# $ source /etc/restic/default.env
# $ restic snapshots
# Thus you don't have to provide all the arguments like
# $ restic --repo ... --password-file ...
source /etc/restic/_global.env
# Below envvar will override those in _global.env
export RESTIC_REPOSITORY="b2:<b2-repo-name>" # TODO fill with your repo name
# What to backup (paths our mountpoints) e.g. "/ /boot /home /mnt/media".
# To backup only your home directory, set "/home/your-user"
export BACKUP_PATHS="" # TODO fill conveniently with one or multiple paths
# Example below of how to dynamically add a path that is mounted e.g. external USB disk.
# restic does not fail if a specified path is not mounted, but it's nicer to only add if they are available.
#test -d /mnt/media && BACKUP_PATHS+=" /mnt/media"
# A tag to identify backup snapshots.
export BACKUP_TAG=systemd.timer
# Retention policy - How many backups to keep.
# See https://restic.readthedocs.io/en/stable/060_forget.html?highlight=month#removing-snapshots-according-to-a-policy
export RETENTION_DAYS=14
export RETENTION_WEEKS=16
export RETENTION_MONTHS=18
export RETENTION_YEARS=3
+1
View File
@@ -0,0 +1 @@
<restic-encryption-password>
-11
View File
@@ -1,11 +0,0 @@
[Unit]
Description=Backup with restic to Backblaze B2
OnFailure=status-email-user@%n.service
Requires=nm-unmetered-connection.service
[Service]
Type=simple
Nice=10
ExecStart=/usr/local/sbin/restic_backup.sh
# $HOME or $XDG_CACHE_HOME must be set for restic to find /root/.cache/restic/
Environment="HOME=/root"
+13
View File
@@ -0,0 +1,13 @@
[Unit]
Description=Backup with restic to Backblaze B2
OnFailure=status-email-user@%n.service
Requires=nm-unmetered-connection.service
[Service]
Type=simple
Nice=10
# $HOME or $XDG_CACHE_HOME must be set for restic to find /root/.cache/restic/
Environment="HOME=/root"
# The random sleep (in seconds) is in the case of multiple backup profiles. Many restic instances started at the same time could case high load or network bandwith usage.
# `systemd-cat` allows showing the restic output to the systemd journal
ExecStart=bash -c 'sleep $(shuf -i 0-300 -n 1) && source /etc/restic/%I.env && /usr/local/sbin/restic_backup.sh | systemd-cat'
@@ -7,4 +7,5 @@ Requires=nm-unmetered-connection.service
[Service]
Type=simple
Nice=10
ExecStart=/usr/local/sbin/restic_check.sh
# `systemd-cat` allows showing the restic output to the systemd journal
ExecStart=bash -c 'source /etc/restic/%I.env && /usr/local/sbin/restic_check.sh | systemd-cat'