Repository Public
1#!/bin/zsh2# =============================================================================3# SP BOUCHER | INFRASTRUCTURE & AUTOMATION4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : MacLustr Identity8# File : infrastructure/gateway/maclustr-identity-offnode.sh9# Module : infrastructure10# Repository : https://git.spboucher.ai/maclustr-identity11# Project Website : https://identity.spboucher.ai12# Created : 2026-12-0113# Last Modified : 2026-12-0114#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: admin@spboucher.ai23# Technical Contact: dev@spboucher.ai24# Security/Admin : admin@spboucher.ai25#26# Copyright (c) 202627# Simon-Pierre Boucher28# All rights reserved where applicable. This file is governed by the29# applicable project license, copyright notices and relevant law.30# Existing third-party rights and notices remain unaffected.31#32# License : None specified (no license file in this repository)33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041# MacLustr Identity : copie hors nœud des sauvegardes chiffrées (M2M32c → M4M64b), lancée chaque jour par la passerelle M1M3242# (LaunchDaemon io.maclustr.maclustr-identity-offnode). Les archives sont chiffrées et authentifiées ; aucune clé n'est copiée.43# La clé de la passerelle est chargée dans un agent jetable et transférée : aucune clé privée ne vit sur les nœuds.44set -uo pipefail45export PATH=/usr/bin:/bin:/usr/sbin:/sbin46LAN=$HOME/dispatch/lan.json47ip() { /usr/bin/python3 -c "import json,sys; print(json.load(open(\"$LAN\"))[\"ips\"][sys.argv[1]])" "$1"; }48SRC=$(ip M2M32c); DST=$(ip M4M64b)49O=(-o ControlPath=none -o BatchMode=yes -o ConnectTimeout=15 -o StrictHostKeyChecking=accept-new)50log() { print -r -- "$(date "+%Y-%m-%dT%H:%M:%S") $*"; }51eval "$(ssh-agent -s)" >/dev/null; trap "ssh-agent -k >/dev/null" EXIT52ssh-add -q $HOME/.ssh/id_ed25519 || { log "impossible de charger la clé de la passerelle"; exit 1; }53log "copie M2M32c($SRC) -> M4M64b($DST)"54ssh $O $DST "mkdir -p -m 700 ~/backups-offnode/maclustr-identity" || { log "destination injoignable"; exit 1; }55ssh -A $O $SRC "rsync -a --include 'db-*.dump.gcm' --exclude '*' -e \"ssh -o BatchMode=yes -o ConnectTimeout=15 -o StrictHostKeyChecking=accept-new\" ~/backups/maclustr-identity/ ${DST}:backups-offnode/maclustr-identity/" || { log "rsync en échec"; exit 1; }56# La copie n'est pas un miroir : une archive effacée sur le nœud reste ici. On garde les 90 plus récentes.57ssh $O $DST "ls -1t ~/backups-offnode/maclustr-identity/db-*.dump.gcm 2>/dev/null | tail -n +91 | xargs -r rm -f"58N=$(ssh $O $DST "ls ~/backups-offnode/maclustr-identity/db-*.dump.gcm 2>/dev/null | wc -l" | tr -d " ")59LAST=$(ssh $O $DST "ls -1t ~/backups-offnode/maclustr-identity/db-*.dump.gcm 2>/dev/null | head -1 | xargs -I{} basename {}")60ssh $O $SRC "date +%s > ~/backups/maclustr-identity/last-offnode" 61log "terminé : $N archive(s) hors nœud, la plus récente $LAST"62