Backup of ~/.openclaw/ (configs + workspace) to a private GitHub repo via cron.
Workspace has its own .git managed by OpenClaw, so this tool snapshots it
(without .git) into workspace-snapshot/ before each commit. Everything else
in ~/.openclaw/ is tracked directly.
git,rsync,crontab- A private GitHub repo for your backups (create it via github.com)
Generate a dedicated key (no passphrase — required for cron):
ssh-keygen -t ed25519 -f ~/.ssh/openclaw-backup -N "" -C "openclaw-backup"Add it as a deploy key with write access in your backup repo:
github.com → your backup repo → Settings → Deploy keys → Add deploy key
Configure SSH to use this key. Add to ~/.ssh/config:
Host openclaw-backup
HostName github.com
User git
IdentityFile ~/.ssh/openclaw-backup
IdentitiesOnly yes
git clone https://github.com/AlexeyKrasnoperov/openclaw-backup.git ~/openclaw-backup
cd ~/openclaw-backup
chmod +x setup.sh
./setup.sh openclaw-backup:your-username/my-openclaw-data.git
# Custom frequency (every 30 min instead of default 60)
./setup.sh openclaw-backup:your-username/my-openclaw-data.git 30| File | Purpose |
|---|---|
setup.sh |
One-time provisioning: git init, remote, cron |
backup.sh |
Cron job: snapshot workspace, commit & push |
workspace.gitignore |
Template installed as .gitignore in ~/.openclaw/ |
rsynccopies~/.openclaw/workspace/→~/.openclaw/workspace-snapshot/(excluding.git)git add -Astages everything in~/.openclaw/(workspace is in.gitignore, snapshot is not)- Commit and push
rm -rf workspace-snapshot/
This way OpenClaw's own .git in workspace is never touched.
.gitignoreblocks secrets, credentials, databases, logs- No
sudo, no auto-install - Push timeout (120s) prevents hung cron jobs
- PID lock prevents overlapping runs
- SSH deploy key scoped to one repo
git clone openclaw-backup:your-username/my-openclaw-data.git ~/.openclaw
mv ~/.openclaw/workspace-snapshot ~/.openclaw/workspace
cd ~/.openclaw/workspace && git init -b main
# Reinstall cron
cd ~/openclaw-backup
./setup.sh openclaw-backup:your-username/my-openclaw-data.gitcd ~/.openclaw
git init -b main
git remote add origin openclaw-backup:your-username/my-openclaw-data.git
git fetch origin main
git checkout origin/main -- .
# Restore workspace files (merge with existing)
rsync -a workspace-snapshot/ workspace/
rm -rf workspace-snapshot
# Reinstall cron
cd ~/openclaw-backup
./setup.sh openclaw-backup:your-username/my-openclaw-data.gitcd ~/.openclaw
git log --oneline
git checkout <commit> -- .
rsync -a workspace-snapshot/ workspace/
rm -rf workspace-snapshot- SQLite databases are excluded. If OpenClaw uses SQLite for state,
consider a separate
sqlite3 .dumpstrategy. - All log files are excluded (
*.log). - To change frequency, re-run
./setup.sh <url> <new-minutes>.
crontab -l | grep -v 'openclaw/backup/backup.sh' | crontab -
rm -rf ~/.openclaw/backup ~/.openclaw/.git ~/.openclaw/.gitignore