From 90929224403d2257ed5fe4ee225f36305887e078 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Wed, 6 Sep 2023 17:52:22 +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..8455366 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..7e20f1b 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=("/usr/local/bin/borg create" "--verbose" "--filter AME" "--list" "--stats" "--show-rc" "--compression lz4" "--exclude-caches") +borg_command+=($(exclude)) +borg_command+=("::backup-{hostname}-{now}" "${BORG_TARGETS[@]}") + +"${borg_command[@]}" backup_exit=$?