From 429bcdb1bf0200948fde5778c448fbb5d28fad72 Mon Sep 17 00:00:00 2001 From: Paul Kloppers Date: Tue, 21 Apr 2026 20:37:26 +0200 Subject: [PATCH] Fall back to host tar when container is down MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- backup.sh | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/backup.sh b/backup.sh index 123ef66..ae2e284 100755 --- a/backup.sh +++ b/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 +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 "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}"