Files
claude-code/automation/backup.sh
OpenCode Test f682d781a0 Add session, maintenance, and backup commands
New commands:
- /summarize: Save session decisions/preferences to memory
- /maintain: Configuration maintenance (validate, backup, restore, etc.)

New automation scripts:
- backup.sh: Create timestamped config backup (excludes secrets)
- restore.sh: Restore config from backup (with validation)

Updates:
- component-registry.json: Added new commands
- commands/README.md: Updated with new entries
- automation/README.md: Documented utility scripts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 12:11:52 -08:00

93 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
# Backup Claude Code configuration
# Creates a timestamped archive of important files
set -euo pipefail
CLAUDE_DIR="${HOME}/.claude"
BACKUP_DIR="${CLAUDE_DIR}/backups"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_NAME="claude-config-${TIMESTAMP}"
BACKUP_PATH="${BACKUP_DIR}/${BACKUP_NAME}.tar.gz"
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo "📦 Claude Code Configuration Backup"
echo ""
# Create backup directory
mkdir -p "${BACKUP_DIR}"
# Files to backup (relative to CLAUDE_DIR)
BACKUP_ITEMS=(
"CLAUDE.md"
"README.md"
"settings.json"
".gitignore"
".claude-plugin"
"agents"
"commands"
"hooks"
"skills"
"workflows"
"state"
"automation"
)
# Create temporary directory
TEMP_DIR=$(mktemp -d)
TEMP_BACKUP="${TEMP_DIR}/${BACKUP_NAME}"
mkdir -p "${TEMP_BACKUP}"
echo "Copying files..."
for item in "${BACKUP_ITEMS[@]}"; do
if [[ -e "${CLAUDE_DIR}/${item}" ]]; then
cp -r "${CLAUDE_DIR}/${item}" "${TEMP_BACKUP}/"
echo -e " ${GREEN}${NC} ${item}"
else
echo -e " ${YELLOW}!${NC} ${item} (not found)"
fi
done
# Exclude sensitive files
echo ""
echo "Excluding sensitive files..."
find "${TEMP_BACKUP}" -name "*.key" -delete 2>/dev/null || true
find "${TEMP_BACKUP}" -name "*.pem" -delete 2>/dev/null || true
find "${TEMP_BACKUP}" -name "credentials.json" -delete 2>/dev/null || true
find "${TEMP_BACKUP}" -name "token.json" -delete 2>/dev/null || true
find "${TEMP_BACKUP}" -name "settings.local.json" -delete 2>/dev/null || true
# Create archive
echo ""
echo "Creating archive..."
tar -czf "${BACKUP_PATH}" -C "${TEMP_DIR}" "${BACKUP_NAME}"
# Cleanup
rm -rf "${TEMP_DIR}"
# Get size
SIZE=$(du -h "${BACKUP_PATH}" | cut -f1)
echo ""
echo -e "${GREEN}${NC} Backup complete!"
echo ""
echo "Location: ${BACKUP_PATH}"
echo "Size: ${SIZE}"
echo ""
# List recent backups
echo "Recent backups:"
ls -lht "${BACKUP_DIR}"/*.tar.gz 2>/dev/null | head -5 || echo " (none)"
# Cleanup old backups (keep last 10)
BACKUP_COUNT=$(ls -1 "${BACKUP_DIR}"/*.tar.gz 2>/dev/null | wc -l)
if [[ ${BACKUP_COUNT} -gt 10 ]]; then
echo ""
echo "Cleaning up old backups (keeping last 10)..."
ls -1t "${BACKUP_DIR}"/*.tar.gz | tail -n +11 | xargs rm -f
fi