Backups

Protect your agent's memory with reliable backup and restore procedures.

SQLite Backup

SQLite databases are single files — backup is as simple as copying:

# Hot backup (SQLite supports concurrent reads)
cp mnemosyne.db mnemosyne-backup-$(date +%Y%m%d).db

# With verification
sqlite3 mnemosyne.db ".backup to mnemosyne-backup.db"
sqlite3 mnemosyne-backup.db "PRAGMA integrity_check"

Automated Backups

Using Litestream

# Install
wget https://github.com/benbjohnson/litestream/releases/latest/download/litestream-linux-amd64.deb
sudo dpkg -i litestream-linux-amd64.deb

# Configure /etc/litestream.yml
access-key-id: AKIA...
secret-access-key: ...

dbs:
- path: /data/mnemosyne.db
  replicas:
    - url: s3://mybucket/mnemosyne
      retention: 720h  # 30 days
      snapshot-interval: 24h

# Start
sudo systemctl enable litestream
sudo systemctl start litestream

Using Cron

# Daily backup to S3
0 3 * * * sqlite3 /data/mnemosyne.db ".backup to /tmp/mnemosyne-tmp.db" && aws s3 cp /tmp/mnemosyne-tmp.db s3://backups/mnemosyne-$(date +%Y%m%d).db

Restore

# From file copy
cp mnemosyne-backup-20260425.db mnemosyne.db

# From Litestream
litestream restore -o mnemosyne.db s3://mybucket/mnemosyne

# Verify
sqlite3 mnemosyne.db "PRAGMA integrity_check"

Backup Verification

Always verify backups:

#!/bin/bash
BACKUP_FILE=$1

# Check file exists and is valid SQLite
if ! sqlite3 "$BACKUP_FILE" "PRAGMA integrity_check;" | grep -q "ok"; then
  echo "BACKUP FAILED: integrity check failed"
  exit 1
fi

# Check row counts
WORKING=$(sqlite3 "$BACKUP_FILE" "SELECT COUNT(*) FROM working_memory;")
EPISODIC=$(sqlite3 "$BACKUP_FILE" "SELECT COUNT(*) FROM episodic_memory;")

echo "Backup verified: $WORKING working, $EPISODIC episodic"

Retention Policy

Backup TypeFrequencyRetention
HourlyEvery hour24 hours
DailyEvery day30 days
WeeklyEvery week12 weeks
MonthlyEvery month12 months
Test Restores

A backup you can't restore is worthless. Schedule monthly restore drills to a staging environment.