SPB Git

Repository Public

restore.sh 2.6 KB 53 lines shellscript

1#!/bin/zsh2# =============================================================================3#                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project          : MacLustr SMS Gateway8# File             : scripts/restore.sh9# Module           : scripts10# Repository       : https://git.spboucher.ai/maclustr-sms11# Project Website  : https://sms.spboucher.ai12# Created          : 2026-11-3013# Last Modified    : 2026-11-3014#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# Restauration d'une sauvegarde dans une base (par défaut une base NEUVE, jamais la base de production par accident).42#   usage : scripts/restore.sh <archive.dump.enc> <base_cible>43# Pour remettre en production : arrêter l'app (pm2 stop maclustr-sms), restaurer dans une base neuve, vérifier,44# puis renommer les bases (voir docs/DEPLOYMENT.md § Récupération). La clé de données (data.key) d'origine est indispensable.45set -euo pipefail46export PATH="/opt/homebrew/bin:/opt/homebrew/opt/postgresql@17/bin:/usr/bin:/bin:/usr/sbin:/sbin"47[ $# -eq 2 ] || { echo "usage : $0 <archive.dump.enc> <base_cible>"; exit 2; }48KEY="${MLSMS_BACKUP_KEY:-$HOME/.config/maclustr-sms/backup.key}"49if psql -d postgres -tAc "select 1 from pg_database where datname='$2'" | grep -q 1; then echo "la base $2 existe déjà : choisir un nom neuf"; exit 1; fi50createdb "$2"51openssl enc -d -aes-256-cbc -pbkdf2 -iter 200000 -pass "file:$KEY" -in "$1" | pg_restore --no-owner -d "$2"52echo "restauré dans $2 : $(psql -tAc 'select count(*) from messages' "$2") message(s), $(psql -tAc 'select count(*) from devices' "$2") appareil(s)"53
Files main
Menu

Theme