From b5932f7d6cd069168e9aa3988b7ca694e53f4ff8 Mon Sep 17 00:00:00 2001 From: Jiri Uhlir Date: Mon, 8 Jun 2026 10:20:36 +0200 Subject: [PATCH] Fix restore script on clean target server --- scripts/restore-appfactory.sh | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/scripts/restore-appfactory.sh b/scripts/restore-appfactory.sh index a2142e3..7b95828 100755 --- a/scripts/restore-appfactory.sh +++ b/scripts/restore-appfactory.sh @@ -51,9 +51,7 @@ command -v docker >/dev/null 2>&1 || fail "docker missing" APPFACTORY_UID="$(id -u "$TARGET_USER")" APPFACTORY_GID="$(id -g "$TARGET_USER")" -if [ ! -S /var/run/docker.sock ]; then - fail "Docker socket missing: /var/run/docker.sock" -fi +[ -S /var/run/docker.sock ] || fail "Docker socket missing: /var/run/docker.sock" APPFACTORY_DOCKER_GID="$(stat -c '%g' /var/run/docker.sock)" @@ -64,11 +62,22 @@ log "APPFACTORY_GID=$APPFACTORY_GID" log "APPFACTORY_DOCKER_GID=$APPFACTORY_DOCKER_GID" log "Stopping existing AppFactory containers if present" -docker ps -a --format '{{.Names}}' | grep -E '^(appfactory-|.*-service$|test-|microsoft-365-service)' | while read -r container; do - [ -n "$container" ] || continue - docker rm -f "$container" >/dev/null 2>&1 || true - echo "[restore] Removed container: $container" -done + +mapfile -t APPFACTORY_CONTAINERS < <( + docker ps -a --format '{{.Names}}' \ + | grep -E '^(appfactory-|.*-service$|test-|microsoft-365-service)' \ + || true +) + +if [ "${#APPFACTORY_CONTAINERS[@]}" -eq 0 ]; then + ok "No existing AppFactory containers found" +else + for container in "${APPFACTORY_CONTAINERS[@]}"; do + [ -n "$container" ] || continue + docker rm -f "$container" >/dev/null 2>&1 || true + ok "Removed container: $container" + done +fi log "Removing existing AppFactory root" rm -rf "$APPFACTORY_ROOT" @@ -80,9 +89,7 @@ log "Extracting backup" cd / tar -xzf "$BACKUP_FILE" -if [ ! -d "$APPFACTORY_ROOT" ]; then - fail "Backup did not create $APPFACTORY_ROOT" -fi +[ -d "$APPFACTORY_ROOT" ] || fail "Backup did not create $APPFACTORY_ROOT" log "Ensuring required directories" mkdir -p \ @@ -99,9 +106,7 @@ mkdir -p \ ENV_FILE="$APPFACTORY_ROOT/config/appfactory.env" -if [ ! -f "$ENV_FILE" ]; then - fail "Missing env file after restore: $ENV_FILE" -fi +[ -f "$ENV_FILE" ] || fail "Missing env file after restore: $ENV_FILE" log "Updating runtime ids in appfactory.env"