scripts/refresh-legacy-report-tables.sh: dumps only the 4 tables the overpriced-internet report needs (account/delivery/service/product) from the live legacy DB with --single-transaction (non-locking), verifies the dump is complete before importing into the local legacy-db copy. ~20MB, seconds. Creds read from a prod-only .refresh.env (gitignored; .env.example committed). Used to refresh the copy from the 2026-05-22 snapshot to current (service 66741→69233, account 15321→15706). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
50 lines
2.5 KiB
Bash
50 lines
2.5 KiB
Bash
#!/usr/bin/env bash
|
|
# refresh-legacy-report-tables.sh
|
|
# ---------------------------------------------------------------------------
|
|
# Rafraîchit, dans la copie locale `legacy-db`, UNIQUEMENT les tables dont le
|
|
# rapport « Internet cher » (lib/legacy-reports.js) a besoin, à partir de la
|
|
# base de facturation LEGACY live (10.100.80.100).
|
|
#
|
|
# Pourquoi ciblé : la base complète fait ~6 Go (ticket_msg, factures,
|
|
# écritures comptables…), inutile ici. Les 4 tables du rapport font ~20 Mo →
|
|
# dump + import en quelques secondes. `--single-transaction` = snapshot InnoDB
|
|
# cohérent, NON bloquant (n'interrompt pas la facturation en prod).
|
|
#
|
|
# Sécurité : le dump est écrit dans un fichier temporaire, VÉRIFIÉ complet
|
|
# ("Dump completed") AVANT d'importer — un dump tronqué n'écrase jamais la copie.
|
|
#
|
|
# Identifiants : lus depuis un fichier .refresh.env voisin (NON versionné).
|
|
# Voir refresh-legacy-report-tables.env.example. À exécuter sur l'hôte prod
|
|
# (96.125.196.67), qui seul peut joindre 10.100.80.100 et le conteneur legacy-db.
|
|
# ---------------------------------------------------------------------------
|
|
set -uo pipefail
|
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
[ -f "$HERE/.refresh.env" ] && . "$HERE/.refresh.env"
|
|
|
|
SRC_HOST="${SRC_HOST:-10.100.80.100}"
|
|
DB_NAME="${DB_NAME:-gestionclient}"
|
|
TABLES="${TABLES:-account delivery service product}"
|
|
CONTAINER="${CONTAINER:-legacy-db}"
|
|
: "${SRC_SSH_PW:?SRC_SSH_PW manquant — voir .refresh.env}"
|
|
: "${DB_PW:?DB_PW manquant — voir .refresh.env}"
|
|
|
|
TMP="$(mktemp /tmp/legacy-refresh.XXXXXX.sql)"
|
|
trap 'rm -f "$TMP"' EXIT
|
|
|
|
echo "[refresh] dump ciblé ($TABLES) depuis $SRC_HOST ..."
|
|
sshpass -p "$SRC_SSH_PW" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=15 "root@$SRC_HOST" \
|
|
"MYSQL_PWD='$DB_PW' mysqldump --single-transaction --quick -uroot $DB_NAME $TABLES" > "$TMP"
|
|
|
|
SZ="$(wc -c <"$TMP")"
|
|
if ! tail -c 200 "$TMP" | grep -q "Dump completed"; then
|
|
echo "[refresh] ✗ dump INCOMPLET ($SZ octets) — import ANNULÉ (copie intacte)"; exit 1
|
|
fi
|
|
echo "[refresh] dump complet ($SZ octets) — import dans '$CONTAINER' ..."
|
|
|
|
docker exec -i -e MYSQL_PWD="$DB_PW" "$CONTAINER" mariadb -uroot "$DB_NAME" < "$TMP"
|
|
|
|
echo "[refresh] ✓ terminé — état de la copie :"
|
|
docker exec -e MYSQL_PWD="$DB_PW" "$CONTAINER" mariadb -uroot -N "$DB_NAME" -e \
|
|
"SELECT CONCAT(' service=',COUNT(*),' max(date_orig)=',FROM_UNIXTIME(MAX(date_orig))) FROM service;
|
|
SELECT CONCAT(' account=',COUNT(*),' delivery=',(SELECT COUNT(*) FROM delivery),' product=',(SELECT COUNT(*) FROM product)) FROM account;"
|