From 90697cdb623a2eb37810a8ed1811f41682ae0b67 Mon Sep 17 00:00:00 2001 From: Paul Kloppers Date: Tue, 21 Apr 2026 20:36:27 +0200 Subject: [PATCH] Run world archive via docker exec Stream tar from inside the container to the host, so all server interaction (rcon + archive) happens through docker exec. Requires the container to be running; fails fast otherwise. --- backup.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/backup.sh b/backup.sh index 325190c..123ef66 100755 --- a/backup.sh +++ b/backup.sh @@ -1,7 +1,7 @@ #!/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. +# Requires the minecraft container to be running. set -euo pipefail cd "$(dirname "$0")" @@ -13,17 +13,18 @@ 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." +if ! docker ps --format '{{.Names}}' | grep -qx minecraft; then + echo "Error: minecraft container is not running." >&2 + exit 1 fi -echo "Archiving data/world -> ${OUT}" -tar -czf "${OUT}" -C data world +echo "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}" echo "Done." ls -lh "${OUT}"