diff options
author | TheMightyV <themightyv@protonmail.com> | 2022-01-02 20:12:27 +0100 |
---|---|---|
committer | TheMightyV <themightyv@protonmail.com> | 2022-01-02 20:12:27 +0100 |
commit | de4fc74d50d536f524aa4c65e270123bfe8ef893 (patch) | |
tree | 977cda9219a434d5d4f8618fc7accde7cb7ef7d3 /server.sh | |
parent | 4baf9150016177582dd56a1bf3c09a3cad5aa050 (diff) | |
download | minecraft-server-tools-de4fc74d50d536f524aa4c65e270123bfe8ef893.tar.gz |
added backup restoration
Diffstat (limited to 'server.sh')
-rwxr-xr-x | server.sh | 54 |
1 files changed, 53 insertions, 1 deletions
@@ -232,6 +232,56 @@ function ls_backups() { fi } +# TODO: replace dmenu with terminal-only option +function server_restore() { + REMOTES=$( IFS=$'\n'; echo "${BACKUP_DIRS[*]}" ) + REMOTE=$(echo "$REMOTES" | dmenu -l 30 -p "Select a remote to get snapshot from") + if [[ ! "$REMOTES" == *"${REMOTE}"* ]] || [ ! "$REMOTE" ] ; then + echo "No remote selected, abort" + return 1 + fi + + SNAPSHOTS=$( + if [ $BACKUP_BACKEND = "bup" ]; then + bup_ls_remote "$REMOTE" + elif [ $BACKUP_BACKEND = "borg" ]; then + borg_ls_remote "$REMOTE" + else + tar_ls_remote "$REMOTE" + fi + ) + SNAPSHOT=$(echo "$SNAPSHOTS" | dmenu -l 30 -p "Select a snapshot to recover") + if [[ ! "$SNAPSHOTS" == *"${SNAPSHOT}"* ]] || [ ! "$SNAPSHOT" ] ; then + echo "No snapshot selected, abort" + return 1 + fi + + echo "Restoring snapshot \"$SNAPSHOT\" from remote \"$REMOTE\"" + + OLDWORLD_NAME="" + if [[ -d "$WORLD_NAME" ]]; then + echo "bup: Saving old world, just in case" + OLDWORLD_NAME="${WORLD_NAME}.old.$(date +'%F_%H-%M-%S')" + mv -v "$WORLD_NAME" "$OLDWORLD_NAME" + fi + + if [ $BACKUP_BACKEND = "bup" ]; then + bup_restore "$REMOTE" "$SNAPSHOT" + elif [ $BACKUP_BACKEND = "borg" ]; then + borg_restore "$REMOTE" "$SNAPSHOT" + else + tar_restore "$REMOTE" "$SNAPSHOT" + fi + + if [ ! $? -eq 0 ]; then + echo "Restore failed, reverting old world back" + rm -r "$WORLD_NAME" + mv -v "$OLDWORLD_NAME" "$WORLD_NAME" + else + echo "Restore finished" + fi +} + #cd $(dirname $0) case $1 in @@ -247,7 +297,9 @@ case $1 in "backup") server_backup ;; - # TODO: Add restore command + "restore") + server_restore + ;; "status") server_status ;; |