aboutsummaryrefslogtreecommitdiff
path: root/backends/borg.sh
diff options
context:
space:
mode:
authorGravatar TheMightyV <themightyv@protonmail.com> 2022-01-04 20:00:50 +0100
committerGravatar TheMightyV <themightyv@protonmail.com> 2022-01-04 20:00:50 +0100
commitc1bd65a0a37cbed71e3dddfb8d3244c54e3a802c (patch)
tree5f0dccdff60b7cfbdf6476a3810bbe240fb9d9d1 /backends/borg.sh
parent8974233a537d2890d75d398bdbdf5ca73152b23b (diff)
downloadminecraft-server-tools-c1bd65a0a37cbed71e3dddfb8d3244c54e3a802c.tar.gz
local-ized and lower-cased local variables, descending sorting of
snapshots, minor readability changes
Diffstat (limited to 'backends/borg.sh')
-rw-r--r--backends/borg.sh44
1 files changed, 22 insertions, 22 deletions
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}"
}