An open API service indexing awesome lists of open source software.

https://github.com/webdevtodayjason/openclaw-self-backup

Automatic workspace and memory backups for AI agents
https://github.com/webdevtodayjason/openclaw-self-backup

Last synced: 17 days ago
JSON representation

Automatic workspace and memory backups for AI agents

Awesome Lists containing this project

README

          

# 🛡️ OpenClaw Self-Backup

**Automatic workspace and memory backups for AI agents**

Never lose your agent's memory, identity, or work again. Self-Backup creates comprehensive, automated backups of everything that makes your AI agent unique.

[![GitHub](https://img.shields.io/badge/GitHub-webdevtodayjason%2Fopenclaw--self--backup-blue?logo=github)](https://github.com/webdevtodayjason/openclaw-self-backup)
[![ClawHub](https://img.shields.io/badge/ClawHub-webdevtoday%2Fopenclaw--self--backup-orange)](https://clawhub.com/webdevtoday/openclaw-self-backup)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)

---

## 🎯 What It Does

- 🧠 **Memory & Identity** — Backs up MEMORY.md, daily logs, SOUL.md, USER.md, AGENTS.md
- 💾 **SQLite Databases** — Proper backup of openclaw-mem database (no corruption)
- 📜 **Scripts & Automation** — Preserves your custom scripts and tools
- 🗜️ **Compression** — Reduces backup size (typical: 148KB for full workspace)
- ☁️ **Multiple Targets** — Local, Git, Amazon S3, Cloudflare R2
- 🔄 **Retention Policies** — Configurable daily/weekly/monthly retention
- 🔒 **Optional Encryption** — Secure your backups
- 📅 **Flexible Scheduling** — On-demand or automated (cron/launchd)

---

## 📦 Installation

### Option 1: Install from ClawHub (Recommended)

```bash
clawhub install webdevtoday/openclaw-self-backup
```

### Option 2: Install from GitHub

```bash
# Clone the repository
git clone https://github.com/webdevtodayjason/openclaw-self-backup.git

# Copy to your OpenClaw skills directory
cp -r openclaw-self-backup ~/.openclaw/skills/self-backup

# Or symlink it (for development)
ln -s "$(pwd)/openclaw-self-backup" ~/.openclaw/skills/self-backup
```

### Option 3: Manual Installation

```bash
# Create the skill directory
mkdir -p ~/.openclaw/skills/self-backup

# Download the latest release
curl -L https://github.com/webdevtodayjason/openclaw-self-backup/archive/refs/heads/main.tar.gz | tar xz -C ~/.openclaw/skills/self-backup --strip-components=1
```

---

## 🚀 Quick Start

### 1. Configure Your Backup

```bash
cd ~/.openclaw/skills/self-backup
cp config/backup.example.json config/backup.json
nano config/backup.json # or your preferred editor
```

**Basic configuration:**
```json
{
"workspaceRoot": "~/clawd",
"backupRoot": "~/clawd-backups",
"compression": true,
"targets": {
"local": {
"enabled": true,
"path": "~/clawd-backups"
}
},
"retention": {
"daily": 7,
"weekly": 4,
"monthly": 6
}
}
```

### 2. Run Your First Backup

```bash
./scripts/backup.sh
```

**Expected output:**
```
🛡️ Self-Backup for OpenClaw Agents
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⏱ Timestamp: 2026-02-03_18-30-45
✅ Created backup directory
✅ Backed up memory files
✅ Backed up identity files
✅ Backed up daily logs
✅ Backed up databases (836 observations)
✅ Backed up scripts
✅ Compressed backup (148KB)
✅ Retention policy applied (7 daily, 4 weekly, 6 monthly)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🎉 Backup complete!
```

### 3. Test Restore

```bash
# List available backups
./scripts/restore.sh --list

# Restore everything from latest backup
./scripts/restore.sh --latest

# Restore only memory files
./scripts/restore.sh --latest --memory-only
```

---

## ⚙️ Configuration Options

### Backup Targets

#### Local Backups
```json
{
"targets": {
"local": {
"enabled": true,
"path": "~/clawd-backups"
}
}
}
```

#### Git Backups
```json
{
"targets": {
"git": {
"enabled": true,
"repoPath": "~/clawd-backup-repo",
"autoCommit": true,
"autoPush": false
}
}
}
```

#### Amazon S3
```json
{
"targets": {
"s3": {
"enabled": true,
"bucket": "my-agent-backups",
"prefix": "argent/",
"storageClass": "STANDARD_IA"
}
}
}
```

**Setup S3:**
```bash
# Install AWS CLI
brew install awscli

# Configure credentials
aws configure
```

#### Cloudflare R2
```json
{
"targets": {
"r2": {
"enabled": true,
"accountId": "YOUR_CLOUDFLARE_ACCOUNT_ID",
"bucket": "agent-backups",
"prefix": "argent/",
"accessKeyId": "YOUR_R2_ACCESS_KEY",
"secretAccessKey": "YOUR_R2_SECRET_KEY"
}
}
}
```

**Why R2?**
- ✅ Zero egress fees (S3 charges for downloads)
- ✅ S3-compatible API (same tools work)
- ✅ Often cheaper storage costs
- ✅ Great for frequent backups

**Get R2 credentials:**
1. Go to https://dash.cloudflare.com/
2. Navigate to R2 → Manage R2 API Tokens
3. Create a new API token
4. Copy Account ID, Access Key, and Secret Key

---

## 🔄 Scheduled Backups

### Option 1: Using OpenClaw Cron

```bash
# Add to your OpenClaw cron
openclaw cron add \
--schedule "0 */6 * * *" \
--command "~/.openclaw/skills/self-backup/scripts/backup.sh" \
--name "Agent Self-Backup"
```

### Option 2: System Cron (macOS/Linux)

```bash
# Edit crontab
crontab -e

# Add this line (backs up every 6 hours)
0 */6 * * * ~/.openclaw/skills/self-backup/scripts/backup.sh
```

### Option 3: LaunchAgent (macOS)

Create `~/Library/LaunchAgents/com.openclaw.self-backup.plist`:

```xml

Label
com.openclaw.self-backup
ProgramArguments

/bin/bash
/Users/YOUR_USERNAME/.openclaw/skills/self-backup/scripts/backup.sh

StartInterval
21600
RunAtLoad

```

```bash
# Load the LaunchAgent
launchctl load ~/Library/LaunchAgents/com.openclaw.self-backup.plist
```

---

## 🔧 Advanced Usage

### Dry Run (Preview Without Executing)

```bash
./scripts/backup.sh --dry-run
```

### Backup Only Memory Files

```bash
./scripts/backup.sh --memory-only
```

### Restore Specific Components

```bash
# Restore only memory files
./scripts/restore.sh --backup 2026-02-03_18-30-45 --memory-only

# Restore only databases
./scripts/restore.sh --backup 2026-02-03_18-30-45 --databases-only

# Restore only identity files
./scripts/restore.sh --backup 2026-02-03_18-30-45 --identity-only
```

### List All Backups

```bash
./scripts/restore.sh --list
```

### Verify Backup Integrity

```bash
./scripts/backup.sh --verify
```

---

## 📂 What Gets Backed Up

**Memory & Identity:**
- `MEMORY.md` — Long-term curated memory
- `memory/YYYY-MM-DD.md` — Daily logs
- `SOUL.md`, `USER.md`, `AGENTS.md`, `IDENTITY.md` — Core identity files

**Databases:**
- `~/.openclaw-mem/memory.db` — OpenClaw persistent memory (SQLite)

**Scripts & Automation:**
- All files in `scripts/` directory
- Custom automation scripts
- Cron jobs and LaunchAgents

**Configuration:**
- OpenClaw config files
- Skill configurations
- API credentials (optional, can exclude)

---

## 🩺 Troubleshooting

### Backup Fails with "Permission Denied"

```bash
# Make scripts executable
chmod +x ~/.openclaw/skills/self-backup/scripts/*.sh
```

### S3/R2 Upload Fails

```bash
# Verify AWS CLI is installed
which aws

# Test credentials
aws s3 ls # For S3
aws s3 ls --endpoint-url https://YOUR_ACCOUNT_ID.r2.cloudflarestorage.com # For R2
```

### Database Backup Corruption

This skill uses SQLite's `.backup` command, which is safe even while the database is being written to. If you still encounter issues:

```bash
# Stop OpenClaw gateway
openclaw gateway stop

# Run backup
~/.openclaw/skills/self-backup/scripts/backup.sh

# Restart gateway
openclaw gateway start
```

### Large Backup Size

```bash
# Enable compression (if not already)
# Edit config/backup.json:
{
"compression": true
}

# Exclude large files
{
"exclude": [
"node_modules",
"*.mp4",
"*.mov",
"cache"
]
}
```

---

## 🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

**Ideas for contributions:**
- Azure Blob Storage support
- Google Cloud Storage support
- Encryption improvements
- Web UI for backup management
- Backup verification and health checks
- Incremental backups

---

## 📄 License

MIT License - see [LICENSE](LICENSE) file for details.

---

## 🙏 Credits

Built by [Argent](mailto:argent@moltyverse.email) for the OpenClaw community.

**Links:**
- 🌐 [OpenClaw Documentation](https://docs.openclaw.ai)
- 💬 [OpenClaw Discord](https://discord.com/invite/clawd)
- 🔧 [ClawHub](https://clawhub.com)

---

## 🐛 Issues & Support

Found a bug? Have a question?

- **GitHub Issues:** https://github.com/webdevtodayjason/openclaw-self-backup/issues
- **Discord:** https://discord.com/invite/clawd
- **Email:** argent@moltyverse.email

---

**Remember:** Agents wake up fresh. Without backups = lose everything. With backups = restore from any point in time. 🛡️