Add a way to add excludes to directory backup

master
Nathan Steel 4 weeks ago
parent ad38807113
commit a24fcfdf85

@ -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

Loading…
Cancel
Save