BOC v1.0: RS256 auth, Ledger integration, Prometheus metrics, CI/CD, backup

This commit is contained in:
Bernt
2026-07-28 23:08:32 +00:00
parent 0b4f160af1
commit af874040ca
11541 changed files with 1654104 additions and 1103 deletions
+41
View File
@@ -0,0 +1,41 @@
#!/bin/bash
set -euo pipefail
# BOC Database Backup Script
# Körs varje timme via cron
BACKUP_DIR="/opt/backups/boc"
RETENTION_DAYS=30
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="$BACKUP_DIR/boc_$TIMESTAMP.sql.gz"
# Skapa backup-katalog
mkdir -p "$BACKUP_DIR"
# Backup BOC databas
echo "[$(date)] Starting BOC backup..."
pg_dump -h localhost -U boc_app -d boc --no-password | gzip > "$BACKUP_FILE"
# Verifiera backup
if [ -s "$BACKUP_FILE" ]; then
echo "[$(date)] Backup successful: $BACKUP_FILE ($(du -h "$BACKUP_FILE" | cut -f1))"
else
echo "[$(date)] Backup failed!"
exit 1
fi
# Backup Ledger databas
LEDGER_BACKUP="$BACKUP_DIR/ledger_$TIMESTAMP.sql.gz"
pg_dump -h localhost -U postgres -d aamos_ledger | gzip > "$LEDGER_BACKUP"
if [ -s "$LEDGER_BACKUP" ]; then
echo "[$(date)] Ledger backup successful: $LEDGER_BACKUP"
else
echo "[$(date)] Ledger backup failed!"
fi
# Rensa gamla backups
find "$BACKUP_DIR" -name "boc_*.sql.gz" -mtime +$RETENTION_DAYS -delete
find "$BACKUP_DIR" -name "ledger_*.sql.gz" -mtime +$RETENTION_DAYS -delete
echo "[$(date)] Backup complete. Retention: $RETENTION_DAYS days"
+50
View File
@@ -0,0 +1,50 @@
#!/bin/bash
set -euo pipefail
# BOC Database Restore Script
# Återställer från senaste backup
BACKUP_DIR="/opt/backups/boc"
if [ $# -eq 0 ]; then
# Hitta senaste backup
LATEST_BOC=$(ls -t "$BACKUP_DIR"/boc_*.sql.gz 2>/dev/null | head -1)
LATEST_LEDGER=$(ls -t "$BACKUP_DIR"/ledger_*.sql.gz 2>/dev/null | head -1)
else
LATEST_BOC="$1"
LATEST_LEDGER="${1/boc_/ledger_}"
fi
if [ -z "$LATEST_BOC" ] || [ ! -f "$LATEST_BOC" ]; then
echo "No backup found!"
exit 1
fi
echo "Restoring from: $LATEST_BOC"
# Stoppa BOC
echo "Stopping BOC..."
sudo systemctl stop boc
# Återställ BOC databas
echo "Restoring BOC database..."
gunzip -c "$LATEST_BOC" | psql -h localhost -U boc_app -d boc
# Återställ Ledger databas (om finns)
if [ -n "$LATEST_LEDGER" ] && [ -f "$LATEST_LEDGER" ]; then
echo "Restoring Ledger database..."
gunzip -c "$LATEST_LEDGER" | psql -h localhost -U postgres -d aamos_ledger
fi
# Starta BOC
echo "Starting BOC..."
sudo systemctl start boc
# Verifiera
sleep 3
if curl -sf http://localhost:9094/health > /dev/null; then
echo "Restore successful!"
else
echo "Restore failed - check logs"
exit 1
fi
+11
View File
@@ -0,0 +1,11 @@
#!/bin/bash
# Setup cron jobs for BOC
# Backup varje timme
(crontab -l 2>/dev/null | grep -v "boc/scripts/backup.sh"; echo "0 * * * * /home/bernt/.openclaw/workspace/boc/scripts/backup.sh >> /var/log/boc-backup.log 2>&1") | crontab -
# Health check var 5:e minut
(crontab -l 2>/dev/null | grep -v "health-check"; echo "*/5 * * * * curl -sf http://localhost:9094/health || sudo systemctl restart boc") | crontab -
echo "Cron jobs installed:"
crontab -l | grep boc