Fix restore script on clean target server

This commit is contained in:
2026-06-08 10:20:36 +02:00
parent 5883b13e4f
commit b5932f7d6c
+17 -12
View File
@@ -51,9 +51,7 @@ command -v docker >/dev/null 2>&1 || fail "docker missing"
APPFACTORY_UID="$(id -u "$TARGET_USER")" APPFACTORY_UID="$(id -u "$TARGET_USER")"
APPFACTORY_GID="$(id -g "$TARGET_USER")" APPFACTORY_GID="$(id -g "$TARGET_USER")"
if [ ! -S /var/run/docker.sock ]; then [ -S /var/run/docker.sock ] || fail "Docker socket missing: /var/run/docker.sock"
fail "Docker socket missing: /var/run/docker.sock"
fi
APPFACTORY_DOCKER_GID="$(stat -c '%g' /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 "APPFACTORY_DOCKER_GID=$APPFACTORY_DOCKER_GID"
log "Stopping existing AppFactory containers if present" 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
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 [ -n "$container" ] || continue
docker rm -f "$container" >/dev/null 2>&1 || true docker rm -f "$container" >/dev/null 2>&1 || true
echo "[restore] Removed container: $container" ok "Removed container: $container"
done done
fi
log "Removing existing AppFactory root" log "Removing existing AppFactory root"
rm -rf "$APPFACTORY_ROOT" rm -rf "$APPFACTORY_ROOT"
@@ -80,9 +89,7 @@ log "Extracting backup"
cd / cd /
tar -xzf "$BACKUP_FILE" tar -xzf "$BACKUP_FILE"
if [ ! -d "$APPFACTORY_ROOT" ]; then [ -d "$APPFACTORY_ROOT" ] || fail "Backup did not create $APPFACTORY_ROOT"
fail "Backup did not create $APPFACTORY_ROOT"
fi
log "Ensuring required directories" log "Ensuring required directories"
mkdir -p \ mkdir -p \
@@ -99,9 +106,7 @@ mkdir -p \
ENV_FILE="$APPFACTORY_ROOT/config/appfactory.env" ENV_FILE="$APPFACTORY_ROOT/config/appfactory.env"
if [ ! -f "$ENV_FILE" ]; then [ -f "$ENV_FILE" ] || fail "Missing env file after restore: $ENV_FILE"
fail "Missing env file after restore: $ENV_FILE"
fi
log "Updating runtime ids in appfactory.env" log "Updating runtime ids in appfactory.env"