Backup and restore scripts for opencode, oh-my-opencode, and openclaw configuration files. All secrets are automatically sanitized before backup, making this safe to store in a public Git repository.
# Dry run first (recommended)
./backup.sh --dry-run
# Actual backup with verbose output
./backup.sh -v
# Check what was created
ls -la config/# Interactive restore (asks for confirmation)
./restore.sh -v
# Force restore (no confirmation)
./restore.sh --forceThe following secrets are automatically removed from all backed-up files:
| Secret Type | Pattern | Example |
|---|---|---|
| API Keys | apiKey |
sk-b3a7b522c9ca... |
| Context7 Key | CONTEXT7_API_KEY |
ctx7sk-4d520962-... |
| Bot Tokens | botToken |
461718350:AAHSQ... |
| Gateway Tokens | token, gatewayToken |
74622258fe10f... |
| Socket Tokens | socketToken |
xS4eU919GMaX... |
| Perplexity Key | perplexityApiKey |
pplx-WafEFtXG10... |
These directories and file types are completely excluded for security:
~/.openclaw/identity/β Device authentication tokens~/.openclaw/credentials/β Bot credentials~/.openclaw/telegram/β Telegram bot state and tokens~/.openclaw/logs/β Runtime logs- All
.mdfiles (rules, commands, workspace docs, agent definitions) - All non-JSON configuration files
Only JSON config files are backed up:
| File | Location | Sanitized? |
|---|---|---|
opencode.json |
~/.config/opencode/ |
β Yes |
opencode.json |
~/.opencode/ (if exists) |
β Yes |
openclaw.json |
~/.openclaw/ |
β Yes |
config.json |
~/.config/clawhub/ |
β Yes |
Everything else is excluded β no markdown files, no workspace docs, no agent configs, no plugin data.
backup.shβ Main backup script with sanitizationrestore.shβ Restore from backup with credential promptslib/sanitize.shβ Shared sanitization library
config_files/
βββ backup.sh
βββ restore.sh
βββ lib/
β βββ sanitize.sh
βββ config/ # Created by backup.sh
β βββ opencode/
β β βββ config.json # Sanitized (~/.config/opencode/)
β β βββ opencode-secondary.json # Sanitized (~/.opencode/, if exists)
β βββ openclaw/
β β βββ config.json # Sanitized (~/.openclaw/openclaw.json)
β βββ clawhub/
β βββ config.json # Sanitized (~/.config/clawhub/)
βββ .gitignore
βββ README.md
# Show help
./backup.sh --help
# Dry run (test without changes)
./backup.sh --dry-run
# Verbose output
./backup.sh -v
# Combined
./backup.sh --dry-run -v# Show help
./restore.sh --help
# Verbose restore
./restore.sh -v
# Force overwrite (no confirmation)
./restore.sh --force
# Skip credential prompts (edit manually later)
./restore.sh --skip-credentialsBy default, restore.sh will interactively prompt for ALL required API keys and tokens:
- Context7 API Key (
ctx7sk-...) β Context7 MCP service - Provider API Key (
sk-...) β Model provider (e.g., KIT/scc.kit.edu)
- Model Provider API Key (
sk-...) β Primary model endpoint - Telegram Bot Token (
123456:ABC-...) β From @BotFather - Gateway Auth Token β Device communication authentication
- Perplexity API Key (
pplx-...) β Web search plugin
- Clawhub Registry Token (
clh_4_...) β Plugin registry access
Each prompt hides your input for security. Press Enter to skip any credential (you can edit files manually later, but features won't work).
To skip prompts entirely, use --skip-credentials.
The restore script will automatically prompt for all required credentials after restoring config files.
When you run ./restore.sh, you'll be prompted for each credential listed above.
Tips:
- Press Enter to skip any credential (edit file manually later)
- Input is hidden for security
- Skipped credentials remain as
[REDACTED]in config files
If you skipped credentials or prefer manual editing, edit these files:
~/.config/opencode/opencode.json:
{
"mcp": {
"context7": {
"headers": {
"CONTEXT7_API_KEY": "ctx7sk-YOUR_KEY_HERE"
}
}
},
"provider": {
"KIT": {
"options": {
"apiKey": "sk-YOUR_KEY_HERE"
}
}
}
}~/.openclaw/openclaw.json:
{
"models": {
"providers": {
"custom-ki-toolbox-scc-kit-edu": {
"apiKey": "sk-YOUR_KEY_HERE"
}
}
},
"channels": {
"telegram": {
"botToken": "BOT_TOKEN_HERE"
}
},
"gateway": {
"auth": {
"token": "GATEWAY_TOKEN_HERE"
}
},
"plugins": {
"entries": {
"perplexity": {
"config": {
"webSearch": {
"apiKey": "pplx-YOUR_KEY_HERE"
}
}
}
}
}
}~/.config/clawhub/config.json:
{
"registry": "https://clawhub.ai",
"token": "clh_4_YOUR_TOKEN_HERE"
}After restoring credentials, re-pair your devices:
openclaw wizardOr manually restore ~/.openclaw/identity/ from your secure encrypted backup.
After backup, verify no secrets leaked:
# Scan for common secret patterns
grep -rE 'sk-[a-zA-Z0-9]+' config/
grep -rE 'ctx7sk-[a-zA-Z0-9-]+' config/
grep -rE 'clh_4_[a-zA-Z0-9-]+' config/
grep -rE 'pplx-[a-zA-Z0-9]+' config/
grep -rE '[0-9]{9}:[A-Za-z0-9_-]{35}' config/ # Telegram bot token
# Should return NO resultsThe backup script runs this verification automatically and will fail if secrets are detected.
To exclude additional files:
Add conditions to skip specific files:
if [ -f "$HOME_DIR/.config/opencode/custom.json" ]; then
# Skip this file
log_verbose "Excluding: ~/.config/opencode/custom.json"
fiEdit lib/sanitize.sh to add new secret patterns:
sanitize_customSecret() {
local file="$1"
sed -i -E 's/"customSecret"[[:space:]]*:[[:space:]]*"[^"]+"/"customSecret": "[REDACTED]"/g' "$file"
}Then call it in the appropriate sanitization function.
This project is designed for public sharing. Feel free to:
- Fork and customize for your own setup
- Submit improvements to sanitization patterns
- Add support for additional config locations
- Improve documentation
# Test changes safely
./backup.sh --dry-run -v
# Verify sanitization
./backup.sh
grep -rE 'sk-' config/ # Should find nothing
# Restore to test
./restore.sh --forceMIT License β Use freely, modify as needed, no warranty provided.
This tool is provided as-is. Always:
- Test backups before relying on them
- Keep separate encrypted backups of credentials
- Verify restored configs work in your environment
- Review sanitized files before committing to public repos
You are responsible for ensuring no secrets leak through your backups.