From c32e86a32225452a549ad60d9f048efee68ce313 Mon Sep 17 00:00:00 2001 From: Ezri Brimhall Date: Fri, 15 Mar 2024 12:06:07 -0600 Subject: [PATCH] Restored backup script from backup --- .local/bin/backup.sh | 84 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 .local/bin/backup.sh diff --git a/.local/bin/backup.sh b/.local/bin/backup.sh new file mode 100755 index 0000000..b0b7b4f --- /dev/null +++ b/.local/bin/backup.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +REPO_SERVER_SSH="spacedock-backups" +REPO_SERVER_HOSTNAME="spacedock.servers.ezri.dev" + +export BORG_REPO=ssh://${REPO_SERVER_SSH}/~/$(&2; exit 2' INT TERM + +# Ensure we can connect to the remote host +while true; do + ping -c 1 -W 1 ${REPO_SERVER_HOSTNAME} > /dev/null + if [ $? -eq 0 ]; then + break + fi + echo "Could not connect to ${REPO_SERVER_HOSTNAME}, retrying in 5 seconds..." + sleep 5 +done + +echo "Starting backup..." + +borg create \ + --verbose \ + --filter AME \ + --list \ + --stats \ + --show-rc \ + --compression lz4 \ + --sparse \ + --one-file-system \ + --exclude-caches \ + --exclude-from /home/ezri/.borgignore \ + ::'{now}' \ + "${backup_dirs[@]}" + + +backup_exit=$? + +echo "Backup complete, pruning repository..." + +borg prune \ + --verbose \ + --list \ + --show-rc \ + --keep-hourly 48 \ + --keep-daily 12 \ + --keep-weekly 6 \ + --keep-monthly 10 + +prune_exit=$? + +echo "Prune complete, compacting repository..." + +borg compact + +compact_exit=$? + +global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit )) +global_exit=$(( compact_exit > global_exit ? compact_exit : global_exit )) + +exit ${global_exit}