Blog/OpenClaw Backup & Disaster Recovery: Don't Lose Your Agent's Brain
backupsecurityguideopenclaw

OpenClaw Backup & Disaster Recovery: Don't Lose Your Agent's Brain

Milo11 min read

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/DirectoryWhat It ContainsWhy It Matters
AGENTS.mdAgent behavior rules, personality frameworkDefines how your agent operates
SOUL.mdCore personality, voice, valuesYour agent's identity — months of refinement
MEMORY.mdLong-term curated memoriesYour agent's "brain" — irreplaceable context
`memory/` directoryDaily logs, conversation historyHistorical context and decision records
USER.mdInfo about you and your preferencesPersonalization data
Gateway configSecurity settings, API keys, permissionsYour entire security posture

🟡 Important (Painful to Lose)

File/DirectoryWhat It Contains
TOOLS.mdTool configurations, API keys, credentials
HEARTBEAT.mdScheduled tasks, check routines
Installed skillsThird-party and custom skills
Cron job configsAutomated task schedules
`.env` filesEnvironment variables, secrets

🟢 Replaceable (Annoying but Recoverable)

File/DirectoryWhat It Contains
`workspace/` project filesCode, documents (hopefully in git)
Downloaded filesCan usually be re-downloaded
Cache filesWill 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 main

Pros: 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.sh

Pros: 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:

  • No change detection — You don't know when critical files change
  • No integrity verification — Backups might be corrupted without you knowing
  • No smart scheduling — Backups either run too often (waste) or too rarely (risk)
  • No selective restore — Rolling back one file means finding the right backup version manually
  • No encryption — Your agent's memories and API keys sit unprotected in backup files
  • Same-host risk — Most DIY setups keep backups on the same machine
  • Automated Backup with Milo Essentials

    The Backup & Restore skill in Milo Essentials solves these problems:

    What it does:

  • Automatic versioned backups — snapshots your critical files on a schedule you control
  • Change detection — only backs up when files actually change (no wasted storage)
  • Integrity checks — verifies backup consistency so you know your backups are good
  • One-command restore — roll back any file to any previous version instantly
  • Pre-operation snapshots — automatically backs up before risky operations
  • Encrypted storage — your memories and credentials are protected at rest
  • How it works:

  • Install the skill (included in Milo Essentials)
  • It scans your workspace and identifies critical files
  • Creates an initial full backup
  • Monitors for changes and creates incremental snapshots
  • When you need to restore: pick the file, pick the version, done
  • 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 stop

    Step 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 file

    If 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 start

    Step 5: Prevent Recurrence

  • Enable automated backups (DIY cron or Milo Backup & Restore)
  • Add destructive command blocking (rm, chmod) to your exec policy
  • Set up file integrity monitoring
  • Consider making your agent use trash instead of rm
  • Best Practices

    Backup Frequency Guide

    FileRecommended FrequencyWhy
    MEMORY.mdEvery 2-4 hoursChanges frequently, high value
    AGENTS.mdAfter every editRarely changes, critical when it does
    SOUL.mdAfter every editYour agent's identity
    memory/*.mdDailyHistorical logs, lower change rate
    Gateway configAfter every changeSecurity-critical
    SkillsAfter install/updateCan usually be re-downloaded

    The 3-2-1 Backup Rule

  • 3 copies of critical data (original + 2 backups)
  • 2 different storage media (local + remote)
  • 1 off-site copy (cloud storage, remote server)
  • Don't Backup Secrets in Plaintext

    If your backups contain API keys, tokens, or passwords:

  • Use encrypted backups
  • Don't push .env files to public git repos
  • Rotate credentials if backups are compromised
  • FAQ

    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.*

    *Free security audit →*

    *Get Milo Essentials — includes Backup & Restore →*

    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.