Add manual world backup script
Flushes world via rcon (save-off + save-all flush) before tarring when the server is running; skips the flush and archives as-is when the container is down. Outputs timestamped archives to backups/, which is gitignored.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,6 +13,7 @@ data/.rcon-cli.yaml
|
|||||||
# Backup snapshots
|
# Backup snapshots
|
||||||
data.*.bak/
|
data.*.bak/
|
||||||
*.bak/
|
*.bak/
|
||||||
|
backups/
|
||||||
|
|
||||||
# Port-forward runtime state
|
# Port-forward runtime state
|
||||||
portforward.log
|
portforward.log
|
||||||
|
|||||||
29
backup.sh
Executable file
29
backup.sh
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Usage: ./backup.sh [label]
|
||||||
|
# Creates backups/world-YYYY-MM-DD-HHMM[-label].tar.gz
|
||||||
|
# If the minecraft container is running, flushes world via rcon first.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
LABEL="${1:-}"
|
||||||
|
STAMP="$(date +%Y-%m-%d-%H%M)"
|
||||||
|
SUFFIX="${LABEL:+-$LABEL}"
|
||||||
|
OUT="backups/world-${STAMP}${SUFFIX}.tar.gz"
|
||||||
|
|
||||||
|
mkdir -p backups
|
||||||
|
|
||||||
|
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
|
||||||
|
else
|
||||||
|
echo "Server not running — archiving world as-is."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Archiving data/world -> ${OUT}"
|
||||||
|
tar -czf "${OUT}" -C data world
|
||||||
|
|
||||||
|
echo "Done."
|
||||||
|
ls -lh "${OUT}"
|
||||||
Reference in New Issue
Block a user