From e88b2e86d1b406f41f0b001243e3bb5d5d2122e2 Mon Sep 17 00:00:00 2001 From: St33v Date: Thu, 27 Feb 2020 12:49:15 +1100 Subject: source files moved from /etc/systemd/system/ --- borgAuto.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++- borgBackup.service | 13 +++++++++- borgBackup.timer | 12 ++++++++- 3 files changed, 95 insertions(+), 3 deletions(-) mode change 120000 => 100755 borgAuto.sh mode change 120000 => 100644 borgBackup.service mode change 120000 => 100644 borgBackup.timer diff --git a/borgAuto.sh b/borgAuto.sh deleted file mode 120000 index 398a57c..0000000 --- a/borgAuto.sh +++ /dev/null @@ -1 +0,0 @@ -/etc/systemd/system/borgAuto.sh \ No newline at end of file diff --git a/borgAuto.sh b/borgAuto.sh new file mode 100755 index 0000000..74a3485 --- /dev/null +++ b/borgAuto.sh @@ -0,0 +1,72 @@ +#!/usr/bin/bash +# 8 Sept 2019 SJ Pratt +# Copied from https://blog.andrewkeech.com/posts/170718_borg.html +# the envvar $REPONAME is something you should just hardcode + export BORG_REPO="/mnt/bak/borg" # (now set in ~/.bashrc) + +# DIFF function +# List changes between this archive and the previous one +function Differ { + newArchive=$(borg list :: -P $1 --last 2 --format {name}{NL}) + borg diff ::$newArchive +} + +# Backup all of /home except a few excluded directories and files +echo $'\nCreating St33v\'s archive' +borg create -v --stats --compression auto,lzma,6 \ + ::'{hostname}-{user}-{now:%Y%m%dT%H%M}' \ + /home/st33v \ + /var/log/pacman.log \ + /etc/systemd/system \ + --exclude '/home/st33v/.cache' \ + --exclude '/home/st33v/.local' \ + --exclude '/home/$USER/cargo' \ + --exclude '/home/st33v/.dropbox' \ + --exclude '/home/st33v/.dropbox-dist' \ + --exclude '/home/st33v/.config' \ + --exclude '/home/st33v/.mozilla' \ + --exclude '/home/st33v/.*' \ + --exclude '*.img' \ + --exclude '*.iso' + +Differ cr4y + +# Backup olho +echo $'\nCreating Image archive' +borg create -v --stats --compression none \ + ::'olho-{now:%Y%m%dT%H%M}' /mnt/olho + +# Route the normal process logging to journalctl +2>&1 + +Differ olho + +backup_exit=$? + +# Prune the repo of extra backups +echo $'\nPruning repository' +borg prune --stats \ + --keep-within 3d \ + --keep-daily 14 \ + --keep-weekly 8 \ + --keep-monthly 12 \ + --keep-yearly -1 \ + :: +prune_exit=$? + +# Include the remaining device capacity in the log +echo $(df -hl | grep --color=never /mnt/bak) + +# borg list :: --format {name:40}{start}{NL} --sort-by name,timestamp + +# use highest exit code as global exit code +global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit )) + +if [ ${global_exit} -eq 0 ]; then + echo "Backup and Prune finished successfully" +elif [ ${global_exit} -eq 1 ]; then + echo "Backup ($backup_exit) and/or Prune ($prune_exit) finished with warnings" +else + echo "Backup ($backup_exit) and/or Prune ($prune_exit) finished with errors" +fi +exit ${global_exit} diff --git a/borgBackup.service b/borgBackup.service deleted file mode 120000 index e6ab39a..0000000 --- a/borgBackup.service +++ /dev/null @@ -1 +0,0 @@ -/etc/systemd/system/borgBackup.service \ No newline at end of file diff --git a/borgBackup.service b/borgBackup.service new file mode 100644 index 0000000..fa08c6a --- /dev/null +++ b/borgBackup.service @@ -0,0 +1,12 @@ +[Unit] +Description=Borg daily backup + +[Service] +Type=simple +Nice=19 +IOSchedulingClass=2 +IOSchedulingPriority=7 +ExecStartPre=-/usr/bin/borg break-lock /mnt/bak/borg +ExecStart=-/etc/systemd/system/borgAuto.sh +User=st33v +Group=st33v diff --git a/borgBackup.timer b/borgBackup.timer deleted file mode 120000 index 3b729a3..0000000 --- a/borgBackup.timer +++ /dev/null @@ -1 +0,0 @@ -/etc/systemd/system/borgBackup.timer \ No newline at end of file diff --git a/borgBackup.timer b/borgBackup.timer new file mode 100644 index 0000000..5a61a06 --- /dev/null +++ b/borgBackup.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Borg Backup Timer + +[Timer] +WakeSystem=false +OnBootSec=3min +OnCalendar=0/3:00:00 +RandomizedDelaySec=10min + +[Install] +WantedBy=timers.target -- cgit v1.3