Fall back to host tar when container is down
When the minecraft container is not running, archive data/world directly from the host instead of failing — the files are already consistent on disk with no process writing to them.
This commit is contained in:
15
backup.sh
15
backup.sh
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: ./backup.sh [label]
|
||||
# Creates backups/world-YYYY-MM-DD-HHMM[-label].tar.gz
|
||||
# Requires the minecraft container to be running.
|
||||
# If the container is running, flushes world via rcon and archives via
|
||||
# docker exec. If not, archives data/world from the host directly.
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
@@ -13,18 +14,18 @@ OUT="backups/world-${STAMP}${SUFFIX}.tar.gz"
|
||||
|
||||
mkdir -p backups
|
||||
|
||||
if ! docker ps --format '{{.Names}}' | grep -qx minecraft; then
|
||||
echo "Error: minecraft container is not running." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Flushing world via rcon..."
|
||||
if docker ps --format '{{.Names}}' | grep -qx minecraft; then
|
||||
echo "Server running — flushing world via rcon..."
|
||||
docker exec minecraft rcon-cli save-off >/dev/null
|
||||
docker exec minecraft rcon-cli save-all flush >/dev/null
|
||||
trap 'docker exec minecraft rcon-cli save-on >/dev/null || true' EXIT
|
||||
|
||||
echo "Archiving /data/world -> ${OUT}"
|
||||
docker exec minecraft tar -czf - -C /data world > "${OUT}"
|
||||
else
|
||||
echo "Server not running — archiving data/world from host."
|
||||
tar -czf "${OUT}" -C data world
|
||||
fi
|
||||
|
||||
echo "Done."
|
||||
ls -lh "${OUT}"
|
||||
|
||||
Reference in New Issue
Block a user