From c1bd65a0a37cbed71e3dddfb8d3244c54e3a802c Mon Sep 17 00:00:00 2001 From: TheMightyV Date: Tue, 4 Jan 2022 20:00:50 +0100 Subject: local-ized and lower-cased local variables, descending sorting of snapshots, minor readability changes --- backends/borg.sh | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'backends/borg.sh') diff --git a/backends/borg.sh b/backends/borg.sh index f5930c8..0b28619 100644 --- a/backends/borg.sh +++ b/backends/borg.sh @@ -1,33 +1,33 @@ function borg_init() { export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND" - for BACKUP_DIR in ${BACKUP_DIRS[*]} + for backup_dir in ${BACKUP_DIRS[*]} do # borg will check if repo exists - borg init --encryption=repokey-blake2 "$BACKUP_DIR" + borg init --encryption=repokey-blake2 "$backup_dir" done } function borg_create_backup() { export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND" - RETCODE=255 - for BACKUP_DIR in ${BACKUP_DIRS[*]} + local retcode=255 + for backup_dir in ${BACKUP_DIRS[*]} do - export BORG_REPO="$BACKUP_DIR" + export BORG_REPO="$backup_dir" trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM - echo "borg: starting backup to \"$BACKUP_DIR\"" + echo "borg: starting backup to \"$backup_dir\"" borg create \ - "${BACKUP_DIR}::${BACKUP_NAME}_$(date +'%F_%H-%M-%S')" \ + "${backup_dir}::${BACKUP_NAME}_$(date +'%F_%H-%M-%S')" \ "$WORLD_NAME" \ --filter AME \ --compression lz4 \ --exclude-caches \ - backup_exit=$? + local backup_exit=$? - echo "borg: pruning repository at \"$BACKUP_DIR\"" + echo "borg: pruning repository at \"$backup_dir\"" borg prune \ --prefix '{hostname}-' \ @@ -36,13 +36,13 @@ function borg_create_backup() { --keep-daily 7 \ --keep-weekly 4 \ --keep-monthly 6 \ - "$BACKUP_DIR" + "$backup_dir" - prune_exit=$? + local prune_exit=$? # use highest exit code as global exit code - global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit )) - RETCODE=$(( global_exit > RETCODE ? global_exit : RETCODE )) + local global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit )) + retcode=$(( global_exit > retcode ? global_exit : retcode )) if [ ${global_exit} -eq 0 ]; then echo "borg: backup and prune finished successfully" @@ -53,29 +53,29 @@ function borg_create_backup() { fi #exit ${global_exit} done - return $RETCODE + return $retcode } # server_restore relies on output format of this function function borg_ls_dir() { export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND" - borg list "$1" | cut -d' ' -f1 + borg list "$1" | cut -d' ' -f1 | sort -r } function borg_ls_all() { export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND" - for BACKUP_DIR in ${BACKUP_DIRS[*]} + for backup_dir in ${BACKUP_DIRS[*]} do - echo "borg: backups in \"$BACKUP_DIR\":" - borg list "$BACKUP_DIR" | cut -d' ' -f1 + echo "borg: backups in \"$backup_dir\":" + borg list "$backup_dir" | cut -d' ' -f1 done } function borg_restore() { export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND" - REMOTE="$1" - SNAPSHOT="$2" + local remote="$1" + local snapshot="$2" - export BORG_REPO="$REMOTE" - borg extract "${REMOTE}::${SNAPSHOT}" + export BORG_REPO="$remote" + borg extract "${remote}::${snapshot}" } -- cgit v1.2.3