SPB Git

Repository Public

backup.sh 2.7 KB 58 lines shellscript

1#!/bin/zsh2# =============================================================================3#                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project          : MacLustr Social Engine & Remote Navigator8# File             : scripts/backup.sh9# Module           : scripts10# Repository       : https://git.spboucher.ai/maclustr-social11# Project Website  : https://social.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# Encrypted backup of business data: PostgreSQL + media + evidence. Browser profiles (cookies) are NEVER included:42# they live in another account's home and a second Mac must log in again by hand.43set -euo pipefail44cd "${0:A:h}/.."45source scripts/prod-env.sh46KEY="$MLS_CONFIG_DIR/backup.key"; [ -s "$KEY" ] || { echo "clé de sauvegarde absente"; exit 1; }47TS=$(date -u +%Y%m%dT%H%M%SZ); OUT="$MLS_BACKUP_DIR/mls-$TS.tar.enc"; TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT48if ! { pg_dump --no-owner --format=custom "$DATABASE_URL" > "$TMP/db.dump" \49  && tar -C "$MLS_DATA_DIR" -cf "$TMP/files.tar" media evidence 2>/dev/null \50  && tar -C "$TMP" -cf - db.dump files.tar | openssl enc -aes-256-cbc -pbkdf2 -iter 200000 -salt -pass "file:$KEY" -out "$OUT"; }; then51  node dist/cli.mjs backup-mark fail "$OUT" 0 || true; echo "sauvegarde ÉCHOUÉE"; exit 152fi53chmod 600 "$OUT"; shasum -a 256 "$OUT" > "$OUT.sha256"54node dist/cli.mjs backup-mark ok "${OUT:t}" "$(stat -f %z "$OUT")"55# Retention: 14 daily archives.56ls -1t "$MLS_BACKUP_DIR"/mls-*.tar.enc 2>/dev/null | tail -n +15 | while read f; do rm -f "$f" "$f.sha256"; done57echo "sauvegarde ok : $OUT ($(du -h "$OUT" | cut -f1))"58
Files main
Menu

Theme