chore(legacy): reusable targeted refresh of report tables from live billing DB
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>
This commit is contained in:
parent
bde7a5ef67
commit
b01cf19db6
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -47,3 +47,7 @@ scripts/migration/ref_invoice.pdf
|
||||||
# Auto-generated backups from scripts/convert-html-to-unlayer.js
|
# Auto-generated backups from scripts/convert-html-to-unlayer.js
|
||||||
services/targo-hub/templates/*.bak-*.json
|
services/targo-hub/templates/*.bak-*.json
|
||||||
services/targo-hub/templates/*.bak-*.html
|
services/targo-hub/templates/*.bak-*.html
|
||||||
|
|
||||||
|
# Legacy refresh creds (prod-only, never commit)
|
||||||
|
.refresh.env
|
||||||
|
**/.refresh.env
|
||||||
|
|
|
||||||
8
scripts/refresh-legacy-report-tables.env.example
Normal file
8
scripts/refresh-legacy-report-tables.env.example
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Copier en .refresh.env (à côté du script, sur l'hôte prod) puis remplir.
|
||||||
|
# chmod 600 .refresh.env — contient des mots de passe, NE PAS versionner.
|
||||||
|
SRC_HOST=10.100.80.100 # base de facturation legacy live
|
||||||
|
SRC_SSH_PW= # mot de passe SSH root de la source
|
||||||
|
DB_PW= # mot de passe MySQL root (source ET copie locale)
|
||||||
|
DB_NAME=gestionclient
|
||||||
|
CONTAINER=legacy-db # nom du conteneur de la copie locale
|
||||||
|
TABLES="account delivery service product"
|
||||||
49
scripts/refresh-legacy-report-tables.sh
Normal file
49
scripts/refresh-legacy-report-tables.sh
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
#!/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;"
|
||||||
Loading…
Reference in New Issue
Block a user