From ec691ebcaf79eaef585c498b5293fbeb69a7881f Mon Sep 17 00:00:00 2001 From: hk Date: Sat, 16 Sep 2017 15:32:21 +0200 Subject: [PATCH] Add systemd configuration --- README.md | 24 +++++++++++++++++++++++- systemd/borgwrapper-backup@.service | 9 +++++++++ systemd/borgwrapper-backup@.timer | 10 ++++++++++ systemd/borgwrapper-verify@.service | 9 +++++++++ systemd/borgwrapper-verify@.timer | 10 ++++++++++ 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 systemd/borgwrapper-backup@.service create mode 100644 systemd/borgwrapper-backup@.timer create mode 100644 systemd/borgwrapper-verify@.service create mode 100644 systemd/borgwrapper-verify@.timer diff --git a/README.md b/README.md index 052c19e..3e19d32 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,29 @@ Ensure restrictive permissions on this file as it exposes the passphrase. chown root. config.sh chmod 600 config.sh -Example cron jobs: +# Scheduling +## systemd +Copy the example systemd [unit files](systemd/) to `/etc/systemd/system/`. Then for each +configuration file in `/etc/borgwrapper/.sh` do: + + systemctl enable borgwrapper-backup@.timer + systemctl enable borgwrapper-verify@.timer + + systemctl start borgwrapper-backup@.timer + systemctl start borgwrapper-verify@.timer + +You can view the backup logs with: + + journalctl -xu borgwrapper-backup@ + journalctl -xu borgwrapper-verify@ + +If you want to run the tasks manually outside the timers you can just start them like usual +services: + + systemctl start borgwrapper-backup@ + systemctl start borgwrapper-verify@ + +## Cron (use only if systemd is not available) # Run the backup daily 23 1 * * * /usr/local/bin/borgwrapper backup diff --git a/systemd/borgwrapper-backup@.service b/systemd/borgwrapper-backup@.service new file mode 100644 index 0000000..c1501f5 --- /dev/null +++ b/systemd/borgwrapper-backup@.service @@ -0,0 +1,9 @@ +[Unit] +Description=Run borgwrapper backup (config: %i) +After=network.target + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/borgwrapper -c /etc/borgwrapper/%i.sh backup +User=root +Group=root diff --git a/systemd/borgwrapper-backup@.timer b/systemd/borgwrapper-backup@.timer new file mode 100644 index 0000000..04448e6 --- /dev/null +++ b/systemd/borgwrapper-backup@.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Start daily borgwrapper backup + +[Timer] +OnCalendar=daily +RandomizedDelaySec=6h +Persistent=true + +[Install] +WantedBy=multi-user.target diff --git a/systemd/borgwrapper-verify@.service b/systemd/borgwrapper-verify@.service new file mode 100644 index 0000000..ed56660 --- /dev/null +++ b/systemd/borgwrapper-verify@.service @@ -0,0 +1,9 @@ +[Unit] +Description=Verify borgwrapper backup (config: %i) +After=network.target borgwrapper-backup@%i.service + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/borgwrapper -c /etc/borgwrapper/%i.sh verify +User=root +Group=root diff --git a/systemd/borgwrapper-verify@.timer b/systemd/borgwrapper-verify@.timer new file mode 100644 index 0000000..1a2a4f7 --- /dev/null +++ b/systemd/borgwrapper-verify@.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Start monthly borgwrapper backup verification + +[Timer] +OnCalendar=monthly +RandomizedDelaySec=14d +Persistent=true + +[Install] +WantedBy=multi-user.target