From 167a47b26a9b3375657eb1c825be90cef229d6b3 Mon Sep 17 00:00:00 2001 From: Ryan Chan Date: Sat, 15 Oct 2022 20:44:26 +0100 Subject: [PATCH] Update backup-host script to include system files --- bin/backup-host | 70 ++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/bin/backup-host b/bin/backup-host index 19ff533..62f63d2 100755 --- a/bin/backup-host +++ b/bin/backup-host @@ -19,50 +19,44 @@ fi export BORG_REMOTE_PATH="borg1" export BORG_REPO="zh1117@zh1117.rsync.net:""$(hostname)" -export BORG_PASSCOMMAND="cat ""$HOME""/.borg-passphrase" - -readonly paths=( - "/home/rycwo" -) -readonly exclude_paths=( - "/home/rycwo/.borg-passphrase" - "/home/rycwo/.cache" - "/home/rycwo/.mozilla" - "/home/rycwo/.secret" - "/home/rycwo/.vagrant.d" - "/home/rycwo/.virtualbox" - "/home/rycwo/go") -exclude_file="$(mktemp)" +export BORG_PASSCOMMAND="cat ""$HOME""/.borg_passphrase" exit_() { - status="$?" - - # Reset the trap for EXIT so that we don't enter an exit loop - trap - EXIT - - rm -f "$exclude_file" - exit "$status" + echo "$(date)"" Backup interrupted" >&2 + exit 2 } - -trap exit_ EXIT INT TERM QUIT +trap exit_ INT TERM # Run borg init if the repo doesn't exist yet borg list > /dev/null 2>&1 || { borg init --encryption "repokey" } -for path in "${exclude_paths[@]}"; do - echo "$path" >> "$exclude_file" -done - -# --stats is a nice option if just running as a script -borg create \ - --verbose \ - --filter AME \ - --list \ - --progress \ - --compression "lzma" \ - --exclude-caches \ - --exclude-from "$exclude_file" \ - "::{hostname}-{now}" \ - "${paths[@]}" +borg create \ + --verbose \ + --filter AME \ + --list \ + --show-rc \ + --stats \ + --progress \ + --compression "lzma" \ + --exclude-caches \ + --exclude "home/*/.cache/*" \ + --exclude "var/tmp/*" \ + "::{hostname}-{now}" \ + /etc \ + /home \ + /root \ + /var + +# Keep 7 end of day, 4 additional end of week archives, +# and an end of month archive for every month +borg prune \ + --list \ + --prefix "{hostname}-" \ + --show-rc \ + --keep-daily 7 \ + --keep-weekly 4 \ + --keep-monthly -1 + +borg compact -- 2.38.5