From b1543275b4e1ff0e1324515eef14ee6b7f67044e Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Wed, 6 Sep 2023 18:01:21 +0200 Subject: [PATCH] implement an environment variable to exclude stuff --- .borg-env.example | 3 +++ borgbackup.sh | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.borg-env.example b/.borg-env.example index 8f6fba6..424b4b9 100644 --- a/.borg-env.example +++ b/.borg-env.example @@ -14,6 +14,9 @@ export BORG_PASSPHRASE="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # This array must containing everything you want to include in the backup export BORG_TARGETS=("$HOME") +# Exclude directories and files +export BORG_EXCLUDE=("$HOME/.config/borg" "$HOME/.cache" "*.db") + # [optional] Use a ntfy service to publish backup results # export NTFY=true diff --git a/borgbackup.sh b/borgbackup.sh index 48eb92a..d4eac33 100755 --- a/borgbackup.sh +++ b/borgbackup.sh @@ -47,20 +47,20 @@ trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM info "Starting backup" +exclude() { + for entry in "${BORG_EXCLUDE[@]}"; do + echo "--exclude $entry" + done +} + # Backup the most important directories into an archive named after # the machine this script is currently running on: -/usr/local/bin/borg create \ - --verbose \ - --filter AME \ - --list \ - --stats \ - --show-rc \ - --compression lz4 \ - --exclude-caches \ - \ - ::"${mode}-{hostname}-{now}" \ - "${BORG_TARGETS[@]}" \ +borg_command=("create" "--verbose" "--filter=AME" "--list" "--stats" "--show-rc" "--compression=lz4" "--exclude-caches") +borg_command+=($(exclude)) +borg_command+=("::backup-{hostname}-{now}" "${BORG_TARGETS[@]}") + +/usr/local/bin/borg "${borg_command[@]}" backup_exit=$?