diff options
author | TheMightyV <themightyv@protonmail.com> | 2022-01-02 19:58:23 +0100 |
---|---|---|
committer | TheMightyV <themightyv@protonmail.com> | 2022-01-02 19:58:23 +0100 |
commit | 57f56df53bb63f23b5f4447046a8f9f725162ad9 (patch) | |
tree | 1f1665bc29c78eb35a6eaa4939ac55e4189ec108 /backends/bup.sh | |
parent | cd32e794b00c04a5b969fd0292c7764e32e25863 (diff) | |
download | minecraft-server-tools-57f56df53bb63f23b5f4447046a8f9f725162ad9.tar.gz |
multiple backup destinations
Diffstat (limited to 'backends/bup.sh')
-rw-r--r-- | backends/bup.sh | 70 |
1 files changed, 55 insertions, 15 deletions
diff --git a/backends/bup.sh b/backends/bup.sh index 83e4e98..e51aaf1 100644 --- a/backends/bup.sh +++ b/backends/bup.sh @@ -1,23 +1,63 @@ -function create_bup_backup() { - BACKUP_DIR="mc-backups" - CUR_BACK_DIR="mc-backups/$CUR_YEAR" - - if [ ! -d "$CUR_BACK_DIR" ]; then - mkdir -p "$CUR_BACK_DIR" - fi +# use first not-remote backup directory as bup's local repository +# defaults to ".bup" +function bup_local() { + for BACKUP_DIR in ${BACKUP_DIRS[*]} + do + if [[ $BACKUP_DIR != *:* ]]; then + echo "$BACKUP_DIR" + return + fi + done + echo ".bup" +} - bup -d "$CUR_BACK_DIR" index "$WORLD_NAME" +function bup_init() { + bup -d "$(bup_local)" index "$WORLD_NAME" status=$? - if [ $status -eq 1 ]; then - bup -d "$CUR_BACK_DIR" init - bup -d "$CUR_BACK_DIR" index "$WORLD_NAME" + if [ $status -ne 0 ]; then + echo "bup: no local repo found, creating..." + bup -d "$(bup_local)" init -r "$(bup_local)" + echo "bup: created local repo at $(bup_local)" fi +} + +function bup_create_backup() { + echo "bup: backup started" + + bup -d "$(bup_local)" index "$WORLD_NAME" - bup -d "$CUR_BACK_DIR" save -n "$BACKUP_NAME" "$WORLD_NAME" + # 0 if saved to at least one non-local repository + RETCODE=1 + for BACKUP_DIR in ${BACKUP_DIRS[*]} + do + echo "bup: backing up to \"$BACKUP_DIR\"" + # try to save to remote + bup -d "$(bup_local)" save -r "$BACKUP_DIR" -n "$BACKUP_NAME" "$WORLD_NAME" + # if failed - reinit remote and try again + if [ ! $? -eq 0 ]; then + echo "bup: failed backing up to \"$BACKUP_DIR\", reinitializing remote..." + bup -d "$(bup_local)" init -r "$BACKUP_DIR" + if [ ! $? -eq 0 ]; then + echo "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" + fi + else + if [ "$BACKUP_DIR" = "$(bup_local)" ]; then + RETCODE=0 + fi + fi + done - echo "Backup using bup to $CUR_BACK_DIR is complete" + echo "bup: backup finished" + return $RETCODE } -function ls_bup() { - bup -d "mc-backups/${CUR_YEAR}" ls "mc-sad-squad/$1" +function bup_ls() { + for BACKUP_DIR in ${BACKUP_DIRS[*]} + do + echo "bup: backups in \"$BACKUP_DIR\":" + bup -d "$(bup_local)" ls -r "$BACKUP_DIR" --human-readable -l "$BACKUP_NAME" + done } |