From bb97797154eb24f98977e749d554a343e721cf14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Sch=C3=A4ferdiek?= Date: Thu, 30 Jun 2022 00:13:32 +0200 Subject: [PATCH] Add restic-report example and systemd service files --- _man/src/dotfiles-system.1.ronn | 18 ++++----- etc/systemd/system/restic-report@.service | 16 ++++++++ etc/systemd/system/restic-report@.timer | 9 +++++ etc/systemd/user/restic-report@.service | 16 ++++++++ etc/systemd/user/restic-report@.timer | 9 +++++ .../doc/dotfiles-system/restic/mybackup/env | 1 + .../dotfiles-system/restic/mybackup/report.sh | 14 +++++++ usr/share/man/man1/dotfiles-system.1 | 37 +++++++------------ 8 files changed, 87 insertions(+), 33 deletions(-) create mode 100644 etc/systemd/system/restic-report@.service create mode 100644 etc/systemd/system/restic-report@.timer create mode 100644 etc/systemd/user/restic-report@.service create mode 100644 etc/systemd/user/restic-report@.timer create mode 100755 usr/share/doc/dotfiles-system/restic/mybackup/report.sh diff --git a/_man/src/dotfiles-system.1.ronn b/_man/src/dotfiles-system.1.ronn index d88a469..dbd1732 100644 --- a/_man/src/dotfiles-system.1.ronn +++ b/_man/src/dotfiles-system.1.ronn @@ -3,15 +3,15 @@ dotfiles-system is a collection of helper systemd services, systemd timers and shell scripts for common configuration and tasks like -* checking if systemd services and timers are running -* borgmatic backup -* restic backup -* checking if docker containers are running -* batch docker-compose upgrades -* docker housekeeping for removing unused docker containers, volumes and images -* dynamic dns update -* update check for pacman -* memory and disk checks + * checking if systemd services and timers are running + * borgmatic backup + * restic backup + * checking if docker containers are running + * batch docker-compose upgrades + * docker housekeeping for removing unused docker containers, volumes and images + * dynamic dns update + * update check for pacman + * memory and disk checks Provided systemd services mostly support mail notifications if they have failed via systemd_failure_notify. diff --git a/etc/systemd/system/restic-report@.service b/etc/systemd/system/restic-report@.service new file mode 100644 index 0000000..fa408ab --- /dev/null +++ b/etc/systemd/system/restic-report@.service @@ -0,0 +1,16 @@ +[Unit] +Description=Run restic report script for %I utilizing /etc/restic/%I/report.sh file using env /etc/restic/%I/env +OnFailure=systemd_failure_notify@%n.service +Wants=network-online.target +After=network-online.target +Requires=network-online.target + +[Service] +Type=oneshot +ExecStart=sh /etc/restic/%I/report.sh +Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:%h/.bin" +Environment="SSH_AUTH_SOCK=/run/user/%u/keyring/ssh" +EnvironmentFile=/etc/restic/%I/env + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/etc/systemd/system/restic-report@.timer b/etc/systemd/system/restic-report@.timer new file mode 100644 index 0000000..2ddeba2 --- /dev/null +++ b/etc/systemd/system/restic-report@.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Run restic report script for %I utilizing /etc/restic/%I/report.sh file using env /etc/restic/%I/env + +[Timer] +OnCalendar=Sun 01:00:00 +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/etc/systemd/user/restic-report@.service b/etc/systemd/user/restic-report@.service new file mode 100644 index 0000000..6cb83da --- /dev/null +++ b/etc/systemd/user/restic-report@.service @@ -0,0 +1,16 @@ +[Unit] +Description=Run restic report script for %I utilizing ~/.config/restic/%I/report.sh file using env ~/.config/restic/%I/env +OnFailure=systemd_failure_notify@%n.service +Wants=network-online.target +After=network-online.target +Requires=network-online.target + +[Service] +Type=oneshot +ExecStart=sh %h/.config/restic/%I/report.sh +Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:%h/.bin" +Environment="SSH_AUTH_SOCK=/run/user/%u/keyring/ssh" +EnvironmentFile=%h/.config/restic/%I/env + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/etc/systemd/user/restic-report@.timer b/etc/systemd/user/restic-report@.timer new file mode 100644 index 0000000..37da8c0 --- /dev/null +++ b/etc/systemd/user/restic-report@.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Run restic report script for %I utilizing ~/.config/restic/%I/report.sh file using env ~/.config/restic/%I/env + +[Timer] +OnCalendar=Sun 01:00:00 +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/usr/share/doc/dotfiles-system/restic/mybackup/env b/usr/share/doc/dotfiles-system/restic/mybackup/env index 71d19b3..7ca1f46 100644 --- a/usr/share/doc/dotfiles-system/restic/mybackup/env +++ b/usr/share/doc/dotfiles-system/restic/mybackup/env @@ -16,3 +16,4 @@ RESTIC_KEEP="--keep-daily 7 --keep-weekly 4 --keep-monthly 3" # advanced parameters RESTIC_ADDITIONAL_CREATE_PARAMS="--one-file-system" +#RESTIC_REPORT_MAIL=monitoring@mydomain.tld diff --git a/usr/share/doc/dotfiles-system/restic/mybackup/report.sh b/usr/share/doc/dotfiles-system/restic/mybackup/report.sh new file mode 100755 index 0000000..0f5dadf --- /dev/null +++ b/usr/share/doc/dotfiles-system/restic/mybackup/report.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# adapt to your needs +# this serves as an example and assumes configured mailx + +SNAPSHOTS=$(/usr/bin/restic snapshots -c) +STATS=$(/usr/bin/restic stats) + +# output for stdin (service) +echo -e "$STATS\n\n$SNAPSHOTS" + +# output for mail +me="$0" +echo -e "$STATS\n\n$SNAPSHOTS" | mailx -Ssendwait -s "[restic - $(hostname)] $me - REPORT" "${RESTIC_REPORT_MAIL}" diff --git a/usr/share/man/man1/dotfiles-system.1 b/usr/share/man/man1/dotfiles-system.1 index ee1a447..9bc4d84 100644 --- a/usr/share/man/man1/dotfiles-system.1 +++ b/usr/share/man/man1/dotfiles-system.1 @@ -2,32 +2,21 @@ .\" http://github.com/rtomayko/ronn/tree/0.7.3 dotfiles\-system is a collection of helper systemd services, systemd timers and shell scripts for common configuration and tasks like . -.IP "\(bu" 4 -checking if systemd services and timers are running +.IP "" 4 . -.IP "\(bu" 4 -borgmatic backup +.nf + +* checking if systemd services and timers are running +* borgmatic backup +* restic backup +* checking if docker containers are running +* batch docker\-compose upgrades +* docker housekeeping for removing unused docker containers, volumes and images +* dynamic dns update +* update check for pacman +* memory and disk checks . -.IP "\(bu" 4 -restic backup -. -.IP "\(bu" 4 -checking if docker containers are running -. -.IP "\(bu" 4 -batch docker\-compose upgrades -. -.IP "\(bu" 4 -docker housekeeping for removing unused docker containers, volumes and images -. -.IP "\(bu" 4 -dynamic dns update -. -.IP "\(bu" 4 -update check for pacman -. -.IP "\(bu" 4 -memory and disk checks +.fi . .IP "" 0 .