From c3511b23d52594a69c8db75e2b06eb7d41511632 Mon Sep 17 00:00:00 2001 From: Marco Kundt Date: Wed, 11 Nov 2020 14:20:27 +0100 Subject: [PATCH] Revert "remove borg in favour of borgmatic" This reverts commit e7c473264da5c467cd65d68f78c4c3f9dd4461e8. --- borg/.bin/borg_backup | 9 ++++ borg/.bin/borg_common | 46 +++++++++++++++++++ borg/.config/systemd/user/borg-backup.service | 10 ++++ borg/.config/systemd/user/borg-backup.timer | 10 ++++ 4 files changed, 75 insertions(+) create mode 100755 borg/.bin/borg_backup create mode 100755 borg/.bin/borg_common create mode 100644 borg/.config/systemd/user/borg-backup.service create mode 100644 borg/.config/systemd/user/borg-backup.timer diff --git a/borg/.bin/borg_backup b/borg/.bin/borg_backup new file mode 100755 index 0000000..515ff20 --- /dev/null +++ b/borg/.bin/borg_backup @@ -0,0 +1,9 @@ +#!/bin/bash + +source $HOME/.bin/borg_common + +info "Starting backup" +borg create --list --verbose --filter AME --stats --show-rc --compression zstd,3 ::'{hostname}-{now}' $BACKUP_PATHS + +info "Pruning snapshots" +borg prune --list --prefix '{hostname}-' --show-rc --keep-hourly $KEEP_HOURS --keep-daily $KEEP_DAYS --keep-weekly $KEEP_WEEKS --keep-monthly $KEEP_MONTHS --keep-yearly $KEEP_YEARS diff --git a/borg/.bin/borg_common b/borg/.bin/borg_common new file mode 100755 index 0000000..5d9c274 --- /dev/null +++ b/borg/.bin/borg_common @@ -0,0 +1,46 @@ +#!/bin/bash + +read_config() { + # variables + + #BACKUP_PATHS="/etc /home/docker/volumes /root" + #KEEP_HOURS=96 + #KEEP_DAYS=31 + #KEEP_WEEKS=8 + #KEEP_MONTHS=12 + #KEEP_YEARS=3 + #BORG_REPO=ssh://foo@bar:23/dir + #BORG_PASSPHRASE="" + + if [[ ! -f "/etc/borg/env" && ! -f "$HOME/.config/borg/env" && ! -f "./env" ]]; then + echo "no config provided" + exit 1 + fi + + source ./env 2> /dev/null || source $HOME/.config/borg/env 2> /dev/null || source /etc/borg/env 2> /dev/null +} + +info() { printf "\n\e[1m%s\e[0m\n" "$*" >&2; } + +info "Testing if borg is already running..." +if pgrep -x "borg" &> /dev/null; then + echo "borg is already runnning" + exit 1 +fi +echo "Done" + +info "Testing connection..." +ping -c 3 192.168.178.100 &> /dev/null + +if [[ $? > 0 ]]; then + + ping -c 3 1.1.1.1 &> /dev/null + + if [[ $? > 0 ]]; then + info "Not connected." + exit 1 + fi +fi +echo "Done" + +read_config diff --git a/borg/.config/systemd/user/borg-backup.service b/borg/.config/systemd/user/borg-backup.service new file mode 100644 index 0000000..6c63902 --- /dev/null +++ b/borg/.config/systemd/user/borg-backup.service @@ -0,0 +1,10 @@ +[Unit] +Description=borg backup +Before=borg-prune.service + +[Service] +Type=oneshot +ExecStart=%h/.bin/borg_backup + +[Install] +WantedBy=multi-user.target diff --git a/borg/.config/systemd/user/borg-backup.timer b/borg/.config/systemd/user/borg-backup.timer new file mode 100644 index 0000000..a6d8c7d --- /dev/null +++ b/borg/.config/systemd/user/borg-backup.timer @@ -0,0 +1,10 @@ +[Unit] +Description=borg backup + +[Timer] +Persistent=true +OnCalendar=hourly +Unit=borg-backup.service + +[Install] +WantedBy=timers.target