backup-pg : sauvegarder aussi la nouvelle base trouveka_ka (pivot Groupe KA)
1 changed file +16 −12
modified
scripts/ops/backup-pg.sh
+16 −12
@@ -6,30 +6,34 @@ | ||
| 6 | 6 | # pg_dump format custom (compressé, restaurable sélectivement) → |
| 7 | 7 | # ~/trouveka-backups/pg/ + copie croisée sur M2M32b (un node ≠ un backup). |
| 8 | 8 | # Rotation : 7 quotidiennes locales; les dimanches sont gardés 28 jours. |
| 9 | −# Restauration : pg_restore -d trouveka --clean --if-exists <fichier> | |
| 9 | +# Restauration : pg_restore -d <base> --clean --if-exists <fichier> | |
| 10 | +# Pivot 2026-08-23 : deux bases — trouveka (ancien corpus web ouvert, gelé) | |
| 11 | +# et trouveka_ka (moteur Groupe KA, base active). | |
| 10 | 12 | |
| 11 | 13 | PATH="$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" |
| 12 | 14 | export PATH |
| 13 | 15 | DIR="$HOME/trouveka-backups/pg" |
| 14 | 16 | LOG="$HOME/trouveka-backups/backup.log" |
| 15 | 17 | STAMP=$(date '+%Y%m%d') |
| 16 | −OUT="$DIR/trouveka-$STAMP.dump" | |
| 17 | 18 | |
| 18 | 19 | mkdir -p "$DIR" |
| 19 | 20 | log() { echo "$(date '+%F %T') [pg] $*" >> "$LOG"; } |
| 20 | 21 | |
| 21 | −if ! docker exec trouve-ka-postgres-1 pg_dump -U trouveka -d trouveka -Fc > "$OUT.tmp" 2>>"$LOG"; then | |
| 22 | − log "ÉCHEC pg_dump" | |
| 23 | − rm -f "$OUT.tmp" | |
| 24 | − exit 1 | |
| 25 | −fi | |
| 26 | −mv "$OUT.tmp" "$OUT" | |
| 27 | −SIZE=$(du -h "$OUT" | cut -f1) | |
| 28 | −log "dump OK : $OUT ($SIZE)" | |
| 22 | +for DB in trouveka trouveka_ka; do | |
| 23 | + OUT="$DIR/$DB-$STAMP.dump" | |
| 24 | + if ! docker exec trouve-ka-postgres-1 pg_dump -U trouveka -d "$DB" -Fc > "$OUT.tmp" 2>>"$LOG"; then | |
| 25 | + log "ÉCHEC pg_dump ($DB)" | |
| 26 | + rm -f "$OUT.tmp" | |
| 27 | + exit 1 | |
| 28 | + fi | |
| 29 | + mv "$OUT.tmp" "$OUT" | |
| 30 | + SIZE=$(du -h "$OUT" | cut -f1) | |
| 31 | + log "dump OK : $OUT ($SIZE)" | |
| 32 | +done | |
| 29 | 33 | |
| 30 | 34 | # Rotation : quotidiennes > 7 jours supprimées, sauf dimanches gardés 28 jours |
| 31 | −find "$DIR" -name 'trouveka-*.dump' -mtime +7 | while read -r f; do | |
| 32 | − d=$(basename "$f" | sed 's/trouveka-\([0-9]*\)\.dump/\1/') | |
| 35 | +find "$DIR" \( -name 'trouveka-*.dump' -o -name 'trouveka_ka-*.dump' \) -mtime +7 | while read -r f; do | |
| 36 | + d=$(basename "$f" | sed 's/.*-\([0-9]*\)\.dump/\1/') | |
| 33 | 37 | dow=$(date -j -f '%Y%m%d' "$d" '+%u' 2>/dev/null || echo 1) |
| 34 | 38 | if [ "$dow" = "7" ]; then |
| 35 | 39 | find "$f" -mtime +28 -delete 2>/dev/null |
| 36 | 40 | |