From 579ba632d61638794614cfe29150e55a784c980f Mon Sep 17 00:00:00 2001 From: Tobias Trabelsi Date: Mon, 7 Jan 2019 21:56:37 +0100 Subject: [PATCH] made everything a little bit easier to configure --- etc/restic/env.sh | 8 ++++++++ etc/systemd/system/restic-backup.service | 6 ++++-- etc/systemd/system/restic-check.service | 5 ++++- etc/systemd/system/status-email-user@.service | 5 +---- usr/local/sbin/restic_backup.sh | 7 +------ usr/local/sbin/restic_check.sh | 9 +-------- 6 files changed, 19 insertions(+), 21 deletions(-) create mode 100644 etc/restic/env.sh diff --git a/etc/restic/env.sh b/etc/restic/env.sh new file mode 100644 index 0000000..622e70b --- /dev/null +++ b/etc/restic/env.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +export RESTIC_PASSWORD_FILE="/etc/restic/pw.txt" +export RESTIC_REPOSITORY="sftp:lerentis@192.168.0.211:/srv/dev-disk-by-id-md-name-asgard-Data/Backup/Laptop/Huginn" + +# What to backup, and what to not +BACKUP_PATHS="/home/lerentis/" +BACKUP_EXCLUDES="--exclude-file ${BACKUP_PATHS}.backup_exclude" \ No newline at end of file diff --git a/etc/systemd/system/restic-backup.service b/etc/systemd/system/restic-backup.service index 8743058..2ade744 100644 --- a/etc/systemd/system/restic-backup.service +++ b/etc/systemd/system/restic-backup.service @@ -1,10 +1,12 @@ [Unit] -Description=Backup with restic to Backblaze B2 +Description=Backup with restic OnFailure=status-email-user@%n.service [Service] Type=simple Nice=10 +User=lerentis ExecStart=/usr/local/sbin/restic_backup.sh # $HOME or $XDG_CACHE_HOME must be set for restic to find /root/.cache/restic/ -Environment="HOME=/home/lerentis/" \ No newline at end of file +Environment="HOME=/home/lerentis/" +Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket \ No newline at end of file diff --git a/etc/systemd/system/restic-check.service b/etc/systemd/system/restic-check.service index 7f90e78..f9a10d8 100644 --- a/etc/systemd/system/restic-check.service +++ b/etc/systemd/system/restic-check.service @@ -1,9 +1,12 @@ [Unit] -Description=Check restic backup Backblaze B2 for errors +Description=Check restic backup for errors OnFailure=status-email-user@%n.service Conflicts=restic.service [Service] Type=simple +User=lerentis Nice=10 ExecStart=/usr/local/sbin/restic_check.sh +Environment="HOME=/home/lerentis/" +Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket \ No newline at end of file diff --git a/etc/systemd/system/status-email-user@.service b/etc/systemd/system/status-email-user@.service index da45d7b..3c9e868 100644 --- a/etc/systemd/system/status-email-user@.service +++ b/etc/systemd/system/status-email-user@.service @@ -1,8 +1,5 @@ -# Source: https://serverfault.com/questions/876233/how-to-send-an-email-if-a-systemd-service-is-restarted -# Source: https://wiki.archlinux.org/index.php/Systemd/Timers#MAILTO - [Unit] -Description=Send status email for %i to user +Description=Send status popup for %i to user [Service] Type=oneshot diff --git a/usr/local/sbin/restic_backup.sh b/usr/local/sbin/restic_backup.sh index 992c808..5b0922c 100644 --- a/usr/local/sbin/restic_backup.sh +++ b/usr/local/sbin/restic_backup.sh @@ -5,8 +5,7 @@ # Exit on failure, pipe failure set -e -o pipefail -export RESTIC_PASSWORD_FILE="/etc/restic/pw.txt" -export RESTIC_REPOSITORY="sftp:lerentis@asgard.lan:/srv/dev-disk-by-id-md-name-asgard-Data/Backup/Laptop/Huginn" +source /etc/restic/env.sh # Clean up lock if we are killed. # If killed by systemd, like $(systemctl stop restic), then it kills the whole cgroup and all it's subprocesses. @@ -23,10 +22,6 @@ RETENTION_DAYS=14 RETENTION_WEEKS=16 RETENTION_MONTHS=18 RETENTION_YEARS=3 - -# What to backup, and what to not -BACKUP_PATHS="/home/lerentis/" -BACKUP_EXCLUDES="--exclude-file /home/lerentis/.backup_exclude" BACKUP_TAG=systemd.timer diff --git a/usr/local/sbin/restic_check.sh b/usr/local/sbin/restic_check.sh index 2a7941a..4b50467 100644 --- a/usr/local/sbin/restic_check.sh +++ b/usr/local/sbin/restic_check.sh @@ -5,8 +5,7 @@ # Exit on failure, pipe failure set -e -o pipefail -export RESTIC_PASSWORD_FILE="/etc/restic/pw.txt" -export RESTIC_REPOSITORY="sftp:lerentis@asgard.lan:/srv/dev-disk-by-id-md-name-asgard-Data/Backup/Laptop/Huginn" +source /etc/restic/env.sh # Clean up lock if we are killed. # If killed by systemd, like $(systemctl stop restic), then it kills the whole cgroup and all it's subprocesses. @@ -18,12 +17,6 @@ exit_hook() { } trap exit_hook INT TERM - -#source /etc/restic/b2_env.sh - -# How many network connections to set up to B2. Default is 5. -B2_CONNECTIONS=50 - # Remove locks from other stale processes to keep the automated backup running. # NOTE nope, dont' unlock liek restic_backup.sh. restic_backup.sh should take preceedance over this script. #restic unlock &