This repository has been archived on 2026-02-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
openclaw-skills/skills/openclaw-backup/scripts/backup.sh
T
2026-02-09 18:43:33 +08:00

35 lines
938 B
Bash

#!/bin/bash
# OpenClaw Backup Script
# Usage: ./backup.sh [backup_dir]
BACKUP_DIR="${1:-$HOME/openclaw-backups}"
DATE=$(date +%Y-%m-%d_%H%M)
BACKUP_FILE="$BACKUP_DIR/openclaw-$DATE.tar.gz"
mkdir -p "$BACKUP_DIR"
# Create backup (exclude completions cache, logs and temp files)
tar -czf "$BACKUP_FILE" \
--exclude='.openclaw/completions' \
--exclude='.openclaw/*.log' \
--exclude='.openclaw/*.swp' \
--exclude='.openclaw/*.swo' \
--exclude='.openclaw/.openclaw.json.swo' \
-C "$HOME" .openclaw
if [ $? -eq 0 ]; then
SIZE=$(du -h "$BACKUP_FILE" | cut -f1)
# Rotate: keep only last 7 backups
ls -t "$BACKUP_DIR"/openclaw-*.tar.gz 2>/dev/null | tail -n +8 | xargs -r rm
COUNT=$(ls "$BACKUP_DIR"/openclaw-*.tar.gz 2>/dev/null | wc -l)
echo "✅ Backup created: $BACKUP_FILE ($SIZE)"
echo "📁 Total backups: $COUNT"
exit 0
else
echo "❌ Backup failed"
exit 1
fi