22 lignes
1.0 KiB
Bash
22 lignes
1.0 KiB
Bash
#!/usr/bin/env bash
|
|
# Retour arrière d'une migration : retour.sh <dossier-données> <dossier sauvegarde-migration-…>
|
|
set -euo pipefail
|
|
D=$(realpath "$1"); S=$(realpath "$2")
|
|
[ -f "$S/MANIFESTE.json" ] || { echo "MANIFESTE.json absent dans $S"; exit 1; }
|
|
if docker ps --format '{{.Names}}' 2>/dev/null | grep -qx minecraft-neoforge && [ ! -f "$D/COPIE-MIGRATION" ]; then
|
|
echo "REFUS : serveur en ligne"; exit 1; fi
|
|
python3 - "$D" "$S" <<'PY'
|
|
import json,os,shutil,sys
|
|
D,S=sys.argv[1:]; m=json.load(open(os.path.join(S,"MANIFESTE.json")))
|
|
for r in m.get("crees",[]):
|
|
p=os.path.join(D,r)
|
|
if os.path.exists(p): os.remove(p); print("supprimé (créé par migration)",r)
|
|
for r in m["fichiers"]:
|
|
shutil.copy2(os.path.join(S,r),os.path.join(D,r)); print("restauré",r)
|
|
if os.path.exists(os.path.join(D,r)+".avant-migration"): os.remove(os.path.join(D,r)+".avant-migration")
|
|
for r in m.get("crees",[]):
|
|
a=os.path.join(D,r)+".avant-migration"
|
|
if os.path.exists(a): os.remove(a)
|
|
PY
|
|
echo "Retour arrière terminé."
|