diff --git a/g9-migration/journal.md b/g9-migration/journal.md index c4f081c..7ce6f9f 100644 --- a/g9-migration/journal.md +++ b/g9-migration/journal.md @@ -117,3 +117,4 @@ | 2026-10-11 18:40 | J5040 (E4) | Nouvelle clé API OVH créée+souscrite (droits legacy /domain/zone) ; clé NAS expirée confirmée (90 j) | E4 : LE DNS-01 | python-ovh GET /domain/zone/folzocorp.fr/record = 12 records OK ; secrets 600 sur J5040 (ovh.env hors git) ; NAS : mettra la nouvelle clé lors du renouvellement LE | révoquer la clé dans manager OVH | | 2026-10-11 18:45 | J5040 (E4) | Caddy OVH déployé sur .27 : 7/7 certs Let's Encrypt émis (DNS-01) + proxy 6 briques | E4 : TLS auto achève T4.6/S9.1 | maxcryger/caddy-ovh digest 502996b5 healthy ; cloud 302/pass 200/git 200/media 302/photos 502 (stack en copie)/n8n 200/matrix 302, issuer = Let's Encrypt ; WAN (forward Freebox→G9) et démontage edge G9 = après bascule bridge E3 | docker compose down ; révoquer clé | | 2026-10-11 18:10 | 07d : copie parallèle 4 flux (tar par dossier racine) | mono-flux SSH plafonné ~13 Mo/s (lecture HDD NAS, CPU NAS 7% = non saturé) | 29 dirs, xargs -P4 ; + chmod u+rwX post-copie ; intégrité/stack/index = 07d SKIP_COPY=1 | rien (source .25 lecture seule) | +| 2026-10-11 21:30 | 4 | décision chiffrement restic MAINTENU | Critère 3 : arbitrage chiffrement vs simplicité restore | Décision utilisateur : chiffrement restic conservé, clé de repo locale G9 (/etc/restic/repo.key 600, sauvegardée hors repo git), restore simple via sudo restic sur le G9 ; test restore photo prévu par scripts/10-verify-restore-photo.sh | révoquer/cloner la clé si changement de politique | diff --git a/g9-migration/scripts/10-verify-restore-photo.sh b/g9-migration/scripts/10-verify-restore-photo.sh new file mode 100755 index 0000000..6c9c549 --- /dev/null +++ b/g9-migration/scripts/10-verify-restore-photo.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +# 10-verify-restore-photo.sh — Critère 3 : preuve que le snapshot restic contient les photos +# et qu'un fichier photo se restaure à l'identique (sha256 vs source .25). +# +# Chiffrement MAINTENU (décision utilisateur 11/10) : clé de repo locale G9 (/etc/restic/repo.key), +# restore via sudo sur le G9. Source .25 en lecture seule (G4). +# +# Usage : sur la machine de pilotage (détenant la clé), ./10-verify-restore-photo.sh +set -euo pipefail + +XP_USER="Master"; XP_HOST="192.168.1.25"; XP_PORT=222 +XP_PHOTO="/volume1/photo" +G9_USER="folzo"; G9_HOST="192.168.1.24" +KEY="${SSH_KEY:-$HOME/.ssh/id_ed25519_openfox11}" +G9_ORIG="/data/docker/photoprism/originals" +TARGET="/tmp/restore-photo-test" +JOURNAL="$(cd "$(dirname "$0")/.." && pwd)/journal.md" + +SSH_XP="ssh -p $XP_PORT -i $KEY -o ConnectTimeout=10 $XP_USER@$XP_HOST" +SSH_G9="ssh -i $KEY -o ConnectTimeout=10 $G9_USER@$G9_HOST" +RST_PRELUDE='set -a; . /etc/restic.env; set +a' + +log() { echo -e "\n[restore-test] $*"; } +journal() { + printf '| %s | 4 | %s | %s | %s | %s |\n' \ + "$(date '+%Y-%m-%d %H:%M')" "$1" "$2" "$3" "$4" >> "$JOURNAL" +} + +log "=== 1/3 snapshot g9 le plus récent ===" +SNAP=$($SSH_G9 "sudo bash -s" </dev/null | grep -c "$1" +true +EOF +) +[[ "${N:-0}" -gt 0 ]] || { echo "ERREUR : le snapshot $SNAP ne contient pas $G9_ORIG"; exit 1; } +log " ✅ snapshot contient $N entrées sous $G9_ORIG" + +log "=== 2/3 restauration d'un fichier photo ===" +REL=$($SSH_G9 "find '$G9_ORIG' -type f -name '*.jpg' | sort | tail -1") +log "fichier test = ${REL#$G9_ORIG/}" +B64=$(printf '%s' "$REL" | base64 -w0) +$SSH_G9 "sudo bash -s -- '$B64' '$SNAP' '$TARGET'" <<'EOF' +set -a; . /etc/restic.env; set +a +rel=$(printf '%s' "$1" | base64 -d) +rm -rf "$3" +restic -r "$RESTIC_REPOSITORY" restore --target "$3" --path "$rel" "$2" >/dev/null +EOF +$SSH_G9 "sudo bash -s -- '$B64' '$TARGET'" <<'EOF' || { echo "ERREUR : fichier restauré absent"; exit 1; } +rel=$(printf '%s' "$1" | base64 -d) +test -f "$2${rel#/}" +EOF +log "=== 3/3 sha256 restauré vs source .25 ===" +H_SRC=$($SSH_XP "sudo bash -s -- '$B64' '$XP_PHOTO'" <<'EOF' +f=$(printf '%s' "$1" | base64 -d) +sudo sha256sum "$2${f#/data/docker/photoprism/originals}" | cut -d' ' -f1 +EOF +) +H_RST=$($SSH_G9 "sudo bash -s -- '$B64' '$TARGET'" <<'EOF' +f=$(printf '%s' "$1" | base64 -d) +sudo sha256sum "$2${f#/}" | cut -d' ' -f1 +EOF +) +$SSH_G9 "sudo rm -rf '$TARGET'" +if [[ "$H_SRC" == "$H_RST" && -n "$H_SRC" ]]; then + log "✅ sha256 identique : $H_RST" + journal "test restauration photo depuis restic" "Critère 3 : preuve restore du snapshot incluant les photos" "snapshot $SNAP contient $N entrées sous $G9_ORIG ; restore 1 fichier ; sha256 restauré == source .25 (${H_RST:0:12}…) ; chiffrement maintenu (clé locale G9)" "rm -rf $TARGET (fait)" +else + log "❌ sha256 divergents : src=$H_SRC rst=$H_RST" + exit 1 +fi