diff --git a/backup/borg/directory_backup.sh b/backup/borg/directory_backup.sh index fccb9eb..b0cb70b 100644 --- a/backup/borg/directory_backup.sh +++ b/backup/borg/directory_backup.sh @@ -7,13 +7,14 @@ # -r pi2 \ # -R ~/backups/pi1/AA -while getopts d:b:r:R: flag +while getopts d:b:r:R:e: flag do case "${flag}" in d) DIR=${OPTARG};; # Directory to backup b) BACKUP_DIR=${OPTARG};; # Where the backup is on local host r) REMOTE=${OPTARG};; # user@remote or alias (from SSH config), prefer to use alias, as it can deal with port differences R) REMOTE_DIR=${OPTARG};; # Location of remote backup i.e. /backup/borg/HOSTNAME/docker (then /npm, /vaultwarden, etc.) + e) EXCLUDES=${OPTARG};; # Exclude certain directories esac done @@ -28,7 +29,7 @@ borg_backup (){ fi export BORG_REPO=$BACKUP_DIR - borg create ::{hostname}-{now} $DIR + borg create ::{hostname}-{now} $EXCLUDE_FLAGS $DIR } borg_prune () { # Keep last 8 hours of backups, last 3 days, and last 2 weeks. LESS for local to save storage @@ -42,7 +43,7 @@ borg_prune () { } offsite_borg () { export BORG_REPO=$REMOTE:$REMOTE_DIR - borg create ::{hostname}-{now} $DIR # Backup with of the directory itself (seperate borg repo) + borg create ::{hostname}-{now} $EXCLUDE_FLAGS $DIR # Backup with of the directory itself (seperate borg repo) } offsite_prune () { export BORG_REPO=$REMOTE:$REMOTE_DIR @@ -56,9 +57,17 @@ offsite_prune () { # Then compact (actually clear up the disk space of the files removed via prune) borg compact } +# Convert EXCLUDES string to array of "--exclude" flags +build_excludes() { + EXCLUDE_FLAGS="" + for EX in $EXCLUDES; do + EXCLUDE_FLAGS+=" --exclude $EX" + done +} # Script # LOCAL +build_excludes borg_backup borg_prune # Run prune bash script