OpenClaw Backup & Disaster Recovery: Don't Lose Your Agent's Brain
Your Agent Is More Fragile Than You Think
Here's a scenario that happens more often than anyone admits:
You're tweaking your agent's config. You accidentally overwrite MEMORY.md. Or a runaway skill corrupts your AGENTS.md. Or you run rm -rf in the wrong directory. Or your host machine's SSD dies.
Months of carefully curated agent personality, memories, skills, and configuration — gone.
OpenClaw doesn't ship with built-in backup. There's no "undo" button. There's no version history. When something gets deleted or corrupted, it's permanent unless you set up protection.
This guide covers everything you need to know about backing up your OpenClaw agent and recovering from disasters.
What You Need to Back Up
Not all files are equal. Here's a priority breakdown:
🔴 Critical (Lose These = Start Over)
| File/Directory | What It Contains | Why It Matters |
|---|---|---|
AGENTS.md | Agent behavior rules, personality framework | Defines how your agent operates |
SOUL.md | Core personality, voice, values | Your agent's identity — months of refinement |
MEMORY.md | Long-term curated memories | Your agent's "brain" — irreplaceable context |
| `memory/` directory | Daily logs, conversation history | Historical context and decision records |
USER.md | Info about you and your preferences | Personalization data |
| Gateway config | Security settings, API keys, permissions | Your entire security posture |
🟡 Important (Painful to Lose)
| File/Directory | What It Contains |
|---|---|
TOOLS.md | Tool configurations, API keys, credentials |
HEARTBEAT.md | Scheduled tasks, check routines |
| Installed skills | Third-party and custom skills |
| Cron job configs | Automated task schedules |
| `.env` files | Environment variables, secrets |
🟢 Replaceable (Annoying but Recoverable)
| File/Directory | What It Contains |
|---|---|
| `workspace/` project files | Code, documents (hopefully in git) |
| Downloaded files | Can usually be re-downloaded |
| Cache files | Will regenerate |
The 4 Disaster Scenarios
Scenario 1: Accidental Deletion
Cause: You or your agent runs a destructive command. rm MEMORY.md, bad skill execution, or cleaning up the wrong directory.
Frequency: Very common. Happens to ~30% of users within first month.
Recovery without backup: Impossible for memory files. You start from scratch.
Scenario 2: Corruption
Cause: A skill writes bad data into a critical file. A compaction error truncates MEMORY.md. A merge conflict corrupts AGENTS.md.
Frequency: Common. Especially with agents that auto-edit their own files.
Recovery without backup: Partial — you might salvage some content but lose structure.
Scenario 3: Host Failure
Cause: SSD dies. Cloud VM gets terminated. Power failure corrupts filesystem.
Frequency: Rare but catastrophic.
Recovery without backup: Total loss unless your workspace files happen to be in a git repo.
Scenario 4: Security Breach
Cause: Malicious skill exfiltrates or deletes data. Unauthorized access to your agent.
Frequency: Rare but increasing as OpenClaw grows.
Recovery without backup: You don't know what was changed, making recovery impossible even with partial data.
DIY Backup Methods
Method 1: Git Repository (Free, Manual)
The simplest approach — put your workspace in a git repo and commit regularly.
# Initialize git in your workspace
cd ~/.openclaw/workspace
git init
git add AGENTS.md SOUL.md MEMORY.md USER.md TOOLS.md HEARTBEAT.md
git add memory/
git commit -m "Initial backup"
# Set up a private GitHub repo
gh repo create my-agent-backup --private
git remote add origin git@github.com:yourusername/my-agent-backup.git
git push -u origin mainPros: Free, version history, easy to set up.
Cons: Manual (you have to remember to commit), doesn't catch real-time changes, no automation, doesn't backup gateway config or skills separately.
Method 2: Cron-Based Backup Script (Free, Automated)
Write a script that periodically copies critical files to a backup location.
#!/bin/bash
# backup-agent.sh — run via cron every 6 hours
BACKUP_DIR="$HOME/agent-backups/$(date +%Y-%m-%d_%H%M)"
SOURCE="$HOME/.openclaw/workspace"
mkdir -p "$BACKUP_DIR"
# Critical files
cp "$SOURCE/AGENTS.md" "$BACKUP_DIR/" 2>/dev/null
cp "$SOURCE/SOUL.md" "$BACKUP_DIR/" 2>/dev/null
cp "$SOURCE/MEMORY.md" "$BACKUP_DIR/" 2>/dev/null
cp "$SOURCE/USER.md" "$BACKUP_DIR/" 2>/dev/null
cp "$SOURCE/TOOLS.md" "$BACKUP_DIR/" 2>/dev/null
cp "$SOURCE/HEARTBEAT.md" "$BACKUP_DIR/" 2>/dev/null
# Memory directory
cp -r "$SOURCE/memory" "$BACKUP_DIR/" 2>/dev/null
# Skills
cp -r "$HOME/.openclaw/skills" "$BACKUP_DIR/" 2>/dev/null
# Keep only last 30 days of backups
find "$HOME/agent-backups" -maxdepth 1 -type d -mtime +30 -exec rm -rf {} +
echo "Backup complete: $BACKUP_DIR"Add to cron:
crontab -e
# Add: 0 */6 * * * /path/to/backup-agent.shPros: Automated, versioned by timestamp, retains history.
Cons: Backups are on the same machine (useless if host dies), no encryption, no integrity checks, no diff tracking.
Method 3: rsync to Remote (Moderate, Automated)
Push backups to a remote server or cloud storage.
# Sync to a remote backup server
rsync -avz --delete \
~/.openclaw/workspace/ \
user@backup-server:~/openclaw-backup/workspace/
rsync -avz --delete \
~/.openclaw/skills/ \
user@backup-server:~/openclaw-backup/skills/Pros: Off-site backup, survives host failure.
Cons: Requires a second server, --delete can propagate accidental deletions, no point-in-time recovery.
The Problem with DIY Backup
All DIY methods share fundamental weaknesses:
Automated Backup with Milo Essentials
The Backup & Restore skill in Milo Essentials solves these problems:
What it does:
How it works:
Example restore workflow:
You: "My MEMORY.md got corrupted, can you restore it?"
Agent: "I have 12 versions of MEMORY.md. Latest clean version is from
3 hours ago (2,847 tokens). Restoring now... Done.
Current version backed up as memory-md-corrupted-20260224."Recovery Playbook
When disaster strikes, follow this sequence:
Step 1: Stop the Bleeding
# If your agent is running and making things worse, stop it
openclaw gateway stopStep 2: Assess the Damage
# What's missing or changed?
ls -la ~/.openclaw/workspace/
cat ~/.openclaw/workspace/AGENTS.md # Is it intact?
cat ~/.openclaw/workspace/MEMORY.md # Is it intact?Step 3: Restore from Backup
If using git:
cd ~/.openclaw/workspace
git log --oneline # Find the last good commit
git checkout <commit-hash> -- MEMORY.md # Restore specific fileIf using manual backups:
# Find most recent backup
ls -t ~/agent-backups/ | head -5
# Copy back the file you need
cp ~/agent-backups/2026-02-24_0600/MEMORY.md ~/.openclaw/workspace/If using Milo Backup & Restore:
You: "Restore MEMORY.md to the version from this morning"
Agent: "Done. Restored to version from 2026-02-24 08:00 (hash: a3f2b1c)"Step 4: Verify Recovery
# Check file sizes make sense
wc -c ~/.openclaw/workspace/*.md
# Check recent timestamps
ls -la ~/.openclaw/workspace/
# Restart and verify agent behavior
openclaw gateway startStep 5: Prevent Recurrence
rm, chmod) to your exec policytrash instead of rmBest Practices
Backup Frequency Guide
| File | Recommended Frequency | Why |
|---|---|---|
| MEMORY.md | Every 2-4 hours | Changes frequently, high value |
| AGENTS.md | After every edit | Rarely changes, critical when it does |
| SOUL.md | After every edit | Your agent's identity |
| memory/*.md | Daily | Historical logs, lower change rate |
| Gateway config | After every change | Security-critical |
| Skills | After install/update | Can usually be re-downloaded |
The 3-2-1 Backup Rule
Don't Backup Secrets in Plaintext
If your backups contain API keys, tokens, or passwords:
.env files to public git reposFAQ
Q: My agent deleted its own MEMORY.md during a compaction error. How do I prevent this?
Two approaches: (1) Set your agent's exec policy to block rm on *.md files in the workspace directory. (2) Use automated backups so you always have a restore point. Milo Essentials includes both file protection monitoring and automated backup.
Q: How much storage do backups use?
A typical workspace with AGENTS.md, SOUL.md, MEMORY.md, USER.md, TOOLS.md, and 30 daily log files is about 200-500KB total. Even keeping 90 days of daily backups uses under 50MB. Storage is not the bottleneck — remembering to back up is.
Q: Can I back up my agent to a different machine and restore it there?
Yes. Your agent's identity is defined by its workspace files + skills + gateway config. Copy these to a new machine, install OpenClaw, and your agent picks up where it left off. This is also how you migrate between hosts.
Q: What if my backup itself is corrupted?
This is why integrity checks matter. DIY backup scripts don't verify the backup — they just copy bytes. You won't know it's corrupted until you try to restore. Milo's Backup & Restore skill runs integrity checks on every backup to prevent this.
Q: Should I back up the entire `~/.openclaw` directory?
You can, but it's overkill. The ~/.openclaw directory includes cache files, temporary data, and binaries that can be reinstalled. Focus on your workspace (~/.openclaw/workspace/), skills (~/.openclaw/skills/), and gateway configuration.
*Your agent's memories took weeks or months to build. A backup takes minutes to set up. Don't learn this lesson the hard way.*
Keep Reading
OpenClaw Security Guide 2026: How to Lock Down Your AI Agent
A comprehensive guide to securing your OpenClaw deployment. Covers gateway hardening, authentication, exec permissions, skill auditing, and network security. Updated for February 2026.
OpenClaw Alternatives in 2026: A Security-Focused Comparison
OpenClaw's 430,000-line codebase, CVE-2026-25253, and 135,000 exposed instances have developers asking: should I switch? We tested every major alternative through a security lens. Here's what we found.
OpenClaw Gateway Configuration Best Practices (2026 Guide)
Every critical gateway.yaml setting explained — what it does, the recommended value, and what goes wrong if you misconfigure it. Auth modes, rate limiting, model selection, and memory management.
Secure your OpenClaw deployment
Run a free security scan or get Milo Shield for comprehensive automated protection.
Get security updates
New vulnerabilities, hardening guides, and tool updates — straight to your inbox. One email per week, max.