diff options
author | TheMightyV <themightyv@protonmail.com> | 2022-01-04 22:17:50 +0100 |
---|---|---|
committer | TheMightyV <themightyv@protonmail.com> | 2022-01-04 22:17:50 +0100 |
commit | c94132808d2a3499f19f86424bfdedf9e0c39312 (patch) | |
tree | ed77cd2eb5b3f73e10a081918be3ee8e12b53d84 /backends | |
parent | fc9f81108360e528f8adfccf8051c79e089df2c3 (diff) | |
download | minecraft-server-tools-c94132808d2a3499f19f86424bfdedf9e0c39312.tar.gz |
testing backups
hid some messages behind VERBOSE option
unified date formats of tars
Diffstat (limited to 'backends')
-rw-r--r-- | backends/borg.sh | 7 | ||||
-rw-r--r-- | backends/bup.sh | 18 | ||||
-rw-r--r-- | backends/tar.sh | 17 |
3 files changed, 23 insertions, 19 deletions
diff --git a/backends/borg.sh b/backends/borg.sh index 0b28619..5d7b2c7 100644 --- a/backends/borg.sh +++ b/backends/borg.sh @@ -16,7 +16,7 @@ function borg_create_backup() { trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM - echo "borg: starting backup to \"$backup_dir\"" + echo_debug "borg: starting backup to \"$backup_dir\"" borg create \ "${backup_dir}::${BACKUP_NAME}_$(date +'%F_%H-%M-%S')" \ @@ -27,7 +27,7 @@ function borg_create_backup() { local backup_exit=$? - echo "borg: pruning repository at \"$backup_dir\"" + echo_debug "borg: pruning repository at \"$backup_dir\"" borg prune \ --prefix '{hostname}-' \ @@ -45,7 +45,7 @@ function borg_create_backup() { retcode=$(( global_exit > retcode ? global_exit : retcode )) if [ ${global_exit} -eq 0 ]; then - echo "borg: backup and prune finished successfully" + echo_debug "borg: backup and prune finished successfully" elif [ ${global_exit} -eq 1 ]; then echo "borg: backup and/or prune finished with warnings" else @@ -75,6 +75,7 @@ function borg_restore() { export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND" local remote="$1" local snapshot="$2" + local dest="$3" export BORG_REPO="$remote" borg extract "${remote}::${snapshot}" diff --git a/backends/bup.sh b/backends/bup.sh index b57bd86..50c2b86 100644 --- a/backends/bup.sh +++ b/backends/bup.sh @@ -15,14 +15,14 @@ function bup_init() { bup -d "$(bup_local)" index "$WORLD_NAME" local status=$? if [ $status -ne 0 ]; then - echo "bup: no local repo found, creating..." + echo_debug "bup: no local repo found, creating..." bup -d "$(bup_local)" init -r "$(bup_local)" - echo "bup: created local repo at $(bup_local)" + echo_debug "bup: created local repo at $(bup_local)" fi } function bup_create_backup() { - echo "bup: backup started" + echo_debug "bup: backup started" bup -d "$(bup_local)" index "$WORLD_NAME" @@ -31,16 +31,17 @@ function bup_create_backup() { local retcode=1 for backup_dir in ${BACKUP_DIRS[*]} do - echo "bup: backing up to \"$backup_dir\"" + echo_debug "bup: backing up to \"$backup_dir\"" # try to save to remote bup -d "$(bup_local)" save -r "$backup_dir" -n "$BACKUP_NAME" "$WORLD_NAME" local status=$? # if failed - reinit remote and try again if [ $status -ne 0 ]; then - echo "bup: failed backing up to \"$backup_dir\", reinitializing remote..." + echo_debug "bup: failed backing up to \"$backup_dir\", reinitializing remote..." bup -d "$(bup_local)" init -r "$backup_dir" - if [ $? -ne 0 ]; then - echo "bup: created remote at \"$backup_dir\"" + status=$? + if [ $status -ne 0 ]; then + echo_debug "bup: created remote at \"$backup_dir\"" bup -d "$(bup_local)" save -r "$backup_dir" -n "$BACKUP_NAME" "$WORLD_NAME" else echo "bup: failed to make remote at \"$backup_dir\", moving on" @@ -73,5 +74,6 @@ function bup_ls_all() { function bup_restore() { local remote="$1" local snapshot="$2" - bup -d "$(bup_local)" restore -r "$remote" "$BACKUP_NAME/$snapshot/$PWD/." + local dest="$3" + bup -d "$(bup_local)" restore -r "$remote" --outdir "$dest" "$BACKUP_NAME/$snapshot/$PWD/." } diff --git a/backends/tar.sh b/backends/tar.sh index f7ea86e..00018c6 100644 --- a/backends/tar.sh +++ b/backends/tar.sh @@ -5,12 +5,12 @@ function tar_init() { # TODO: Make default .tar with optional bup function tar_create_backup() { - echo "tar: backing up..." + echo_debug "tar: backing up..." local status # save world to a temporary archive - local archname="/tmp/${BACKUP_NAME}_`date +%FT%H%M%S%z`.tar.gz" + local archname="/tmp/${BACKUP_NAME}_`date +%F_%H-%M-%S`.tar.gz" tar -czf "$archname" "./$WORLD_NAME" status=$? if [ $status -ne 0 ]; then @@ -18,14 +18,14 @@ function tar_create_backup() { rm "$archname" #remove (probably faulty) archive return 1 fi - echo "tar: world saved to $archname, pushing it to backup directories..." + echo_debug "tar: world saved to $archname, pushing it to backup directories..." # 0 if could save to at least one backup dir # TODO: make more strict? local retcode=1 for backup_dir in ${BACKUP_DIRS[*]} do - echo "tar: pushing to \"$backup_dir\"" + echo_debug "tar: pushing to \"$backup_dir\"" # scp acts as cp for local destination directories scp "$archname" "$backup_dir/" status=$? @@ -51,22 +51,23 @@ function tar_ls_dir() { local remote="$(echo "$backup_dir" | cut -d: -f1)" local remote_dir="$(echo "$backup_dir" | cut -d: -f2)" ssh "$remote" "ls -1 $remote_dir" | grep "tar.gz" | sort -r - else + else ls -1 "$backup_dir" | grep "tar.gz" | sort -r - fi + fi } function tar_ls_all() { for backup_dir in ${BACKUP_DIRS[*]} do echo "tar: backups in ${backup_dir}:" - tar_ls_remote "$backup_dir" + tar_ls_dir "$backup_dir" done } function tar_restore() { local remote="$1" local snapshot="$2" + local dest="$3" local status scp "$remote/$snapshot" "/tmp/" @@ -76,5 +77,5 @@ function tar_restore() { return 1 fi - tar -xzf "/tmp/$snapshot" + tar -xzf "/tmp/$snapshot" -C "$dest" } |