Introduction
Data backup is the most important yet most easily overlooked aspect of operations. For OpenClaw, losing configuration files, skill plugins, or conversation history can be extremely costly to recover. This tutorial covers what data needs to be backed up, how to automate the backup process, and the complete procedures for disaster recovery and server migration.
What to Back Up
Data Inventory
| Data Type | Location | Importance | Estimated Size |
|---|---|---|---|
| Main configuration file | ~/.config/openclaw/openclaw.json5 |
Critical | < 10 KB |
| Skill files | ~/.openclaw/skills/*.md |
High | 1-50 KB each |
| Conversation history | ~/.openclaw/data/conversations/ |
Medium | Varies by usage |
| MCP configuration | ~/.openclaw/mcp/ |
High | < 100 KB |
| User data | ~/.openclaw/data/users/ |
Medium | Varies by user count |
| Log files | ~/.openclaw/logs/ |
Low | Can be large |
| SSL certificates | /etc/letsencrypt/ or custom path |
High | < 100 KB |
| Environment variables | ~/.bashrc or ~/.env |
Critical | < 5 KB |
Minimum Backup Set
If storage space is limited, back up at least the following:
~/.config/openclaw/openclaw.json5 # Main configuration
~/.openclaw/skills/ # All skills
~/.openclaw/mcp/ # MCP configuration
With these three items, you can quickly restore core functionality even if everything else is lost.
Step 1: Manual Backup
1.1 One-Click Backup Script
Create a simple backup script:
nano ~/openclaw-backup.sh
Add the following content:
#!/bin/bash
# OpenClaw backup script
# Configuration
BACKUP_DIR="$HOME/openclaw-backups"
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="openclaw-backup-${DATE}.tar.gz"
# Create backup directory
mkdir -p "$BACKUP_DIR"
# Paths to back up
PATHS=(
"$HOME/.config/openclaw"
"$HOME/.openclaw/skills"
"$HOME/.openclaw/mcp"
"$HOME/.openclaw/data"
)
# Optional: back up environment variables (only OPENCLAW-related ones)
ENV_FILE="/tmp/openclaw-env-${DATE}.txt"
env | grep -E '^(OPENCLAW_|OPENAI_|ANTHROPIC_|GOOGLE_AI_|DEEPSEEK_|OPENROUTER_)' > "$ENV_FILE"
# Create compressed backup
echo "Starting backup..."
tar -czf "${BACKUP_DIR}/${BACKUP_FILE}" \
"${PATHS[@]}" \
"$ENV_FILE" \
2>/dev/null
# Clean up temporary files
rm -f "$ENV_FILE"
# Calculate backup size
SIZE=$(du -h "${BACKUP_DIR}/${BACKUP_FILE}" | cut -f1)
echo "Backup complete:"
echo " File: ${BACKUP_DIR}/${BACKUP_FILE}"
echo " Size: ${SIZE}"
# Keep the 30 most recent backups, delete older ones
cd "$BACKUP_DIR"
ls -t openclaw-backup-*.tar.gz | tail -n +31 | xargs -r rm
echo "Expired backups cleaned up"
Set permissions and run:
chmod +x ~/openclaw-backup.sh
~/openclaw-backup.sh
1.2 Verify the Backup
# View backup contents
tar -tzf ~/openclaw-backups/openclaw-backup-*.tar.gz | head -20
# Check file integrity
tar -tzf ~/openclaw-backups/openclaw-backup-*.tar.gz > /dev/null && echo "Backup file is intact" || echo "Backup file is corrupted"
Step 2: Automated Backup
2.1 Scheduled Backups with Cron
crontab -e
Add the following entries:
# Daily automatic backup at 2 AM
0 2 * * * /home/your-user/openclaw-backup.sh >> /var/log/openclaw-backup.log 2>&1
# Full backup every Sunday at 3 AM (including logs)
0 3 * * 0 /home/your-user/openclaw-backup-full.sh >> /var/log/openclaw-backup.log 2>&1
2.2 Full Backup Script (Including Logs and Conversation History)
nano ~/openclaw-backup-full.sh
#!/bin/bash
# OpenClaw full backup script (weekly)
BACKUP_DIR="$HOME/openclaw-backups/weekly"
DATE=$(date +%Y%m%d)
BACKUP_FILE="openclaw-full-${DATE}.tar.gz"
mkdir -p "$BACKUP_DIR"
# Pause OpenClaw to ensure data consistency
echo "Pausing OpenClaw service..."
openclaw restart
# Wait for the service to fully stop
sleep 5
# Full backup
echo "Starting full backup..."
tar -czf "${BACKUP_DIR}/${BACKUP_FILE}" \
"$HOME/.config/openclaw" \
"$HOME/.openclaw" \
2>/dev/null
# Restore OpenClaw service
echo "Restoring OpenClaw service..."
openclaw up -d
SIZE=$(du -h "${BACKUP_DIR}/${BACKUP_FILE}" | cut -f1)
echo "Full backup complete: ${SIZE}"
# Keep the 12 most recent weekly backups
cd "$BACKUP_DIR"
ls -t openclaw-full-*.tar.gz | tail -n +13 | xargs -r rm
chmod +x ~/openclaw-backup-full.sh
2.3 Backup to Remote Storage
Local backups alone are not sufficient. We recommend syncing to remote storage:
Method 1: rsync to Another Server
# Add to the end of your backup script
rsync -avz --delete \
"$BACKUP_DIR/" \
backup-user@backup-server:/backups/openclaw/
Method 2: Upload to S3-Compatible Storage
# Install AWS CLI or a compatible tool
# apt install awscli
# Add to the end of your backup script
aws s3 cp "${BACKUP_DIR}/${BACKUP_FILE}" \
s3://your-backup-bucket/openclaw/ \
--storage-class STANDARD_IA
Method 3: Upload to Google Drive / OneDrive
# Using rclone
# apt install rclone
# rclone config (first-time setup required)
rclone copy "${BACKUP_DIR}/${BACKUP_FILE}" \
gdrive:Backups/openclaw/
2.4 Backup Notifications
Add notification functionality to your backup script:
# Send backup notifications through OpenClaw itself (if Telegram is configured)
notify_backup() {
local status=$1
local message=$2
curl -s -X POST "http://localhost:18789/api/notify" \
-H "Content-Type: application/json" \
-d "{\"channel\": \"telegram\", \"user\": \"${ADMIN_TELEGRAM_ID}\", \"message\": \"${message}\"}"
}
# Call after a successful backup
notify_backup "success" "OpenClaw daily backup complete, size: ${SIZE}"
# Call on backup failure
if [ $? -ne 0 ]; then
notify_backup "error" "OpenClaw backup failed, please check the logs"
fi
Step 3: Data Restoration
3.1 Restore Procedure
When you need to restore from a backup, follow these steps:
# Step 1: Stop OpenClaw
openclaw restart
# Step 2: Back up current data (just in case)
mv ~/.config/openclaw ~/.config/openclaw.broken
mv ~/.openclaw ~/.openclaw.broken
# Step 3: Extract the backup file
cd /
tar -xzf ~/openclaw-backups/openclaw-backup-20260404_020000.tar.gz
# Step 4: Restore environment variables (if included in the backup)
cat /tmp/openclaw-env-*.txt
# Manually add the needed environment variables to ~/.bashrc
# Step 5: Reload environment variables
source ~/.bashrc
# Step 6: Start OpenClaw
openclaw up -d
# Step 7: Verify
openclaw doctor
3.2 Partial Restore
If you only need to restore specific data:
# Restore only the configuration file
tar -xzf backup.tar.gz --include='*openclaw.json5' -C /
# Restore only skill files
tar -xzf backup.tar.gz --include='*skills/*' -C /
# Restore only MCP configuration
tar -xzf backup.tar.gz --include='*mcp/*' -C /
3.3 Inspect Backup Contents
Check the backup contents before restoring:
# List all files in the backup
tar -tzf backup.tar.gz
# View a specific file's content (without extracting)
tar -xzf backup.tar.gz -O home/user/.config/openclaw/openclaw.json5
Step 4: Server Migration
4.1 Pre-Migration Preparation
On the old server:
# Create a full backup
~/openclaw-backup-full.sh
# Record the current version
openclaw --version > ~/openclaw-version.txt
# Record the Node.js version
node --version >> ~/openclaw-version.txt
# Export environment variables
env | grep -E '^(OPENCLAW_|OPENAI_|ANTHROPIC_|GOOGLE_AI_|DEEPSEEK_|OPENROUTER_|TELEGRAM_|DISCORD_)' > ~/openclaw-env-export.txt
4.2 Restore on the New Server
# Step 1: Install Node.js 22+
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo bash -
sudo apt install -y nodejs
# Step 2: Install OpenClaw
npm install -g openclaw@latest
# Step 3: Transfer the backup to the new server
scp old-server:~/openclaw-backups/openclaw-full-latest.tar.gz ~/
# Step 4: Restore the data
cd /
tar -xzf ~/openclaw-full-latest.tar.gz
# Step 5: Restore environment variables
scp old-server:~/openclaw-env-export.txt ~/
cat ~/openclaw-env-export.txt >> ~/.bashrc
source ~/.bashrc
# Step 6: Run initialization checks
openclaw doctor
# Step 7: Start the service
openclaw up -d
# Step 8: Verify all channels are working
openclaw logs
4.3 Post-Migration Checklist
| Check Item | Command | Expected Result |
|---|---|---|
| Service status | openclaw doctor |
All checks pass |
| Configuration loaded | openclaw logs |
No errors |
| Model connectivity | Send a test message | Normal response |
| Channel connectivity | Send messages on each channel | Normal send/receive |
| Skills loaded | openclaw skill list |
All skills displayed |
| Dashboard | Access via browser | Login successful |
| HTTPS | curl -I https://your-domain |
200 OK |
4.4 DNS Switchover
If you use a custom domain:
# Update the DNS A record to point to the new server IP
# Do this in your domain registrar's dashboard
# Wait for DNS propagation (typically 5-30 minutes, up to 48 hours)
# Check with the following command
dig ai.example.com +short
# Once confirmed pointing to the new IP, configure SSL on the new server
sudo certbot certonly --standalone -d ai.example.com
Step 5: Disaster Recovery Plan
5.1 The 3-2-1 Backup Rule
Follow the industry-standard 3-2-1 backup rule:
- 3 copies of your data
- 2 different storage media
- 1 off-site backup
Example plan:
Copy 1: Local server ~/openclaw-backups/ (daily automatic)
Copy 2: Remote S3 storage (daily sync)
Copy 3: Local NAS or external drive (weekly, manual or automatic)
5.2 Recovery Time Estimates
| Scenario | Estimated Time | Action |
|---|---|---|
| Configuration file corrupted | 5-10 minutes | Restore config from backup |
| Skill files lost | 5 minutes | Restore skills directory from backup |
| Entire .openclaw directory lost | 15-30 minutes | Restore full backup |
| Server failure | 30-60 minutes | New server + backup restore |
| Data center outage | 1-2 hours | Off-site recovery |
5.3 Quick Recovery Script
Create a one-click recovery script for rapid execution during disasters:
nano ~/openclaw-restore.sh
#!/bin/bash
# OpenClaw one-click restore script
set -e
BACKUP_DIR="$HOME/openclaw-backups"
# Find the latest backup
LATEST_BACKUP=$(ls -t "$BACKUP_DIR"/openclaw-backup-*.tar.gz 2>/dev/null | head -1)
if [ -z "$LATEST_BACKUP" ]; then
echo "Error: No backup files found"
exit 1
fi
echo "Will restore from the following backup:"
echo " $LATEST_BACKUP"
echo " Created: $(stat -c %y "$LATEST_BACKUP" 2>/dev/null || stat -f %Sm "$LATEST_BACKUP")"
echo ""
read -p "Confirm restore? (y/N) " confirm
if [ "$confirm" != "y" ]; then
echo "Cancelled"
exit 0
fi
# Stop the service
echo "Stopping OpenClaw..."
openclaw restart 2>/dev/null || true
# Back up current state
echo "Backing up current state..."
if [ -d "$HOME/.openclaw" ]; then
mv "$HOME/.openclaw" "$HOME/.openclaw.pre-restore.$(date +%s)"
fi
if [ -d "$HOME/.config/openclaw" ]; then
mv "$HOME/.config/openclaw" "$HOME/.config/openclaw.pre-restore.$(date +%s)"
fi
# Restore
echo "Restoring backup data..."
cd /
tar -xzf "$LATEST_BACKUP"
# Start the service
echo "Starting OpenClaw..."
source ~/.bashrc
openclaw up -d
# Verify
echo "Verifying service status..."
sleep 3
openclaw doctor
echo ""
echo "Restore complete!"
chmod +x ~/openclaw-restore.sh
Backup Monitoring
Verify That Backups Are Running Properly
# Check the timestamp of the latest backup
ls -lt ~/openclaw-backups/ | head -5
# Check backup cron logs
tail -20 /var/log/openclaw-backup.log
# Verify backup file sizes (too small may indicate incomplete backups)
du -sh ~/openclaw-backups/openclaw-backup-*.tar.gz | tail -5
Periodic Recovery Drills
We recommend performing a recovery drill every quarter to ensure backups are usable:
# Restore in a test environment
mkdir -p /tmp/openclaw-test-restore
cd /tmp/openclaw-test-restore
tar -xzf ~/openclaw-backups/openclaw-backup-latest.tar.gz
echo "Recovery test passed"
rm -rf /tmp/openclaw-test-restore
FAQ
Backup Files Are Too Large
Conversation history can make backup files very large. Solution:
# Back up only core configuration, excluding conversation history
tar -czf backup.tar.gz \
~/.config/openclaw \
~/.openclaw/skills \
~/.openclaw/mcp \
--exclude='*.log' \
--exclude='conversations'
Channels Cannot Connect After Restore
This is usually because environment variables were not properly restored. Check:
# Confirm key environment variables exist
echo $TELEGRAM_BOT_TOKEN
echo $OPENAI_API_KEY
If they are empty, you need to set the environment variables again.
Cross-Platform Migration (Linux to a Different Linux Distribution)
OpenClaw data is cross-platform compatible. As long as the Node.js version is consistent (22+), backup files can be restored on any Linux distribution.
Summary
Data backup is the last line of defense for ensuring stable OpenClaw operation. Key recommendations: use automated scripts for daily backups, maintain at least one off-site backup copy, and perform regular recovery drills. Configuration files and skill files are the most critical backup targets, and restoring them takes only a few minutes. Remember the 3-2-1 rule so your AI assistant can quickly recover from any unexpected situation.