Files
AgapHost/openai/backup-llm-dbs.sh
alvis f67a5bee67 openai: OpenClaw plugins, memory migration tooling, backup and GPU scripts
Plugins for the Adolf gateway:
  - hindsight-openclaw-plugin: expanded memory recall/retain surface for the
    Cognee -> Hindsight migration
  - todoist-capture-plugin: posts captured ideas to agap-mcp's /capture-idea,
    sending the kb#180 bearer token when AGAP_MCP_TOKEN is present
  - feedback-loop-openclaw-plugin, kimi-quota-footer-plugin, cognee-mcp,
    cognee-openclaw-plugin

Plus migrate-adolf-memory-banks.mjs for the memory-bank split,
backup-hindsight-adolf.sh / backup-llm-dbs.sh (the Hindsight and adolf-state
backups that were previously missing), and gpu_preload_check.sh for the
GTX 1070 residency checks.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-30 04:41:53 +00:00

66 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# Backup script for litellm-db and langfuse-db (openai stack postgres containers).
# litellm-db holds provisioned virtual keys + spend; langfuse-db holds all traces.
# Mirrors the seafile/vaultwarden backup.sh pattern (same repo): dump via
# `docker exec <container> pg_dump`, gzip, retention of last 5, Zabbix freshness
# trapper item per DB. Uses pg_dump (safe against a live/running DB, no downtime
# needed — unlike gitea's stop-the-world dump).
#
# Run every 3 days via root crontab (same schedule as vaultwarden/seafile), e.g.:
# 0 3 */3 * * /home/alvis/agap_git/openai/backup-llm-dbs.sh >> /mnt/backups/openai-llm-dbs/backup.log 2>&1
#
# Restore (litellm-db example, langfuse-db is identical with its own container/user/db):
# gunzip -c /mnt/backups/openai-llm-dbs/<DATE>/litellm-db.sql.gz | \
# docker exec -i litellm-db psql -U litellm -d litellm
# # For langfuse-db:
# gunzip -c /mnt/backups/openai-llm-dbs/<DATE>/langfuse-db.sql.gz | \
# docker exec -i langfuse-db psql -U langfuse -d langfuse
# # If restoring into a fresh/empty DB, first drop+recreate the DB (or restore
# # to a new container) since the dump is a plain SQL dump, not --clean.
set -euo pipefail
BACKUP_DIR="/mnt/backups/openai-llm-dbs"
ZABBIX_TOKEN_FILE="/root/.zabbix_token"
ZABBIX_URL="http://192.168.1.4:81/api_jsonrpc.php"
DATE=$(date '+%Y%m%d-%H%M')
DEST="$BACKUP_DIR/$DATE"
mkdir -p "$DEST"
notify_zabbix() {
local itemid="$1" label="$2"
if [[ -f "$ZABBIX_TOKEN_FILE" ]]; then
local token now_epoch
token=$(cat "$ZABBIX_TOKEN_FILE")
now_epoch=$(date '+%s')
env -u HTTPS_PROXY -u HTTP_PROXY -u ALL_PROXY -u https_proxy -u http_proxy -u all_proxy \
curl -s -X POST "$ZABBIX_URL" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
-d "{\"jsonrpc\":\"2.0\",\"method\":\"history.push\",\"id\":1,\"params\":{\"itemid\":\"$itemid\",\"value\":$now_epoch}}" > /dev/null \
&& echo "Zabbix notified ($label=$now_epoch)."
else
echo "WARNING: $ZABBIX_TOKEN_FILE not found -- skipped Zabbix freshness push for $label." >&2
fi
}
# --- litellm-db ---
echo "Dumping litellm-db..."
docker exec litellm-db pg_dump -U litellm litellm | gzip > "$DEST/litellm-db.sql.gz"
echo "Dumped: litellm-db -> $DEST/litellm-db.sql.gz"
notify_zabbix "70637" "litellm.db.backup.ts"
# --- langfuse-db ---
echo "Dumping langfuse-db..."
docker exec langfuse-db pg_dump -U langfuse langfuse | gzip > "$DEST/langfuse-db.sql.gz"
echo "Dumped: langfuse-db -> $DEST/langfuse-db.sql.gz"
notify_zabbix "70638" "langfuse.db.backup.ts"
echo "$(date): Backup complete: $DEST"
ls -la "$DEST/"
# Rotate: keep last 5 backups
ls -1dt "$BACKUP_DIR"/[0-9]*-[0-9]* 2>/dev/null | tail -n +6 | xargs -r rm -rf