Files
openclaw-backups/scripts/backup-to-gitea.sh

108 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
# OpenClaw Backup to Gitea
# Backs up workspace + state directory to Gitea repo
set -e
BACKUP_DIR="$HOME/.openclaw/workspace"
STATE_DIR="$HOME/.openclaw"
REPO_DIR="/tmp/openclaw-backup-$$"
GITEA_TOKEN="ba94c160b97c3a0fa5cf528ecc107eb2c8cddaa7"
REPO_URL="http://git:${GITEA_TOKEN}@gitea.kangaroo-eel.ts.net:3000/Anthony/openclaw-backup.git"
LOG_FILE="$HOME/.openclaw/workspace/logs/backup.log"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
# Ensure log directory exists
mkdir -p "$(dirname "$LOG_FILE")"
log "Starting backup..."
# Clean up any old temp repo
rm -rf "$REPO_DIR"
# Clone repo fresh
log "Cloning backup repo..."
git clone "$REPO_URL" "$REPO_DIR"
cd "$REPO_DIR"
# Backup workspace files (at root of repo)
log "Backing up workspace..."
rsync -av --delete \
--exclude='.git' \
--exclude='node_modules' \
--exclude='*.log' \
--exclude='.cache' \
--exclude='.venvs' \
--exclude='tmp' \
"$BACKUP_DIR/" "$REPO_DIR/"
# Update skill tracker before backup
log "Updating skill tracker..."
"$BACKUP_DIR/scripts/skill-tracker.sh" save 2>/dev/null || true
# Backup state directory to openclaw-state/
log "Backing up state directory..."
mkdir -p "$REPO_DIR/openclaw-state"
# Copy critical state files
rsync -av --delete \
--include='openclaw.json' \
--include='cron/' \
--include='cron/**' \
--include='devices/' \
--include='devices/paired.json' \
--exclude='*' \
"$STATE_DIR/" "$REPO_DIR/openclaw-state/"
# Update manifest
log "Updating manifest..."
cat > "$REPO_DIR/BACKUP_MANIFEST.md" <<EOF
# OpenClaw Backup
Generated: $(date '+%Y-%m-%d %H:%M:%S')
## Contents
- skills/ - All installed skills and configs
- automations/ - Custom automations (morning briefing, etc.)
- memory/ - Long-term memory and daily notes
- *.md - Core configuration files
- openclaw-state/ - CRITICAL: Gateway config, cron jobs, skills metadata
- openclaw.json - Gateway config (models, plugins, channels)
- cron/jobs.json - All cron jobs
- devices/paired.json - Paired devices
- .installed-skills.json - Skill tracker for auto-recovery after updates
## CRITICAL: Restore Order
1. Clone this repo
2. Copy openclaw-state/openclaw.json to ~/.openclaw/openclaw.json
3. Copy openclaw-state/cron/jobs.json to ~/.openclaw/cron/jobs.json
4. Copy openclaw-state/devices/paired.json to ~/.openclaw/devices/paired.json
5. Copy workspace files to ~/.openclaw/workspace/
6. Restart OpenClaw gateway
7. Run: ~/.openclaw/workspace/scripts/skill-tracker.sh restore
(This auto-reinstalls any skills lost during updates!)
## CRITICAL Credentials to Save Separately (NOT in this repo)
Store these separately in a secure password manager!
- All API keys from Notion database
- WhatsApp session tokens
- Any keys in ~/.config/
EOF
# Configure git
git config user.email "krillyclaw@gmail.com"
git config user.name "Krilly the Crab"
# Commit and push
log "Committing changes..."
git add -A
git diff --cached --quiet || git commit -m "Backup: $(date '+%Y-%m-%d %H:%M:%S')"
git push origin main
log "Backup complete!"
# Clean up
rm -rf "$REPO_DIR"