47 lines
1.2 KiB
Bash
47 lines
1.2 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
set -eo pipefail
|
|
|
|
RCLONE_CONFIG="rclone.conf"
|
|
RCLONE_TARGET="minecraft:"
|
|
WORLDS_DIR="spigot/worlds"
|
|
WORLDS_DIR_BACKUP="$WORLDS_DIR.backup"
|
|
ARCHIVE_PREFIX="etc/mcserver/worlds"
|
|
SERVICE_NAME="spigot"
|
|
|
|
archive=$(rclone --config "$RCLONE_CONFIG" lsf "$RCLONE_TARGET" | sort --reverse | fzf --cycle)
|
|
|
|
if [[ -z $archive ]]; then
|
|
echo "error: no archive file has been selected!" >&2
|
|
exit 1
|
|
fi
|
|
|
|
target_dir=$(mktemp --directory)
|
|
target_archive="$target_dir/$archive"
|
|
|
|
echo "Downloading archive $archive to $target_archive ..."
|
|
rclone --config "$RCLONE_CONFIG" copy "$RCLONE_TARGET$archive" "$target_dir" --progress
|
|
|
|
if [[ -d $WORLDS_DIR_BACKUP ]]; then
|
|
echo "Deleting old worlds dir backup ($WORLDS_DIR_BACKUP) ..."
|
|
rm -rf "$WORLDS_DIR_BACKUP"
|
|
fi
|
|
|
|
echo "Un-zipping archive to $target_dir ..."
|
|
unzip "$target_archive" -d "$target_dir" 1>/dev/null
|
|
|
|
echo "Stopping server ..."
|
|
docker compose stop "$SERVICE_NAME"
|
|
|
|
echo "Backing up worlds dir ($WORLDS_DIR -> $WORLDS_DIR_BACKUP) ..."
|
|
mv "$WORLDS_DIR" "$WORLDS_DIR_BACKUP"
|
|
|
|
echo "Restoring world ($target_dir/$ARCHIVE_PREFIX -> $WORLDS_DIR) ..."
|
|
mv "$target_dir/$ARCHIVE_PREFIX" "$WORLDS_DIR"
|
|
|
|
echo "Re-starting server ..."
|
|
docker compose start "$SERVICE_NAME"
|
|
|
|
echo "Cleaning up ..."
|
|
rm -rf "$target_dir"
|