Initial backup 2026-02-17
This commit is contained in:
58
automations/backup-to-gitea.sh
Executable file
58
automations/backup-to-gitea.sh
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
# Daily backup script for OpenClaw workspace to GitTea
|
||||
|
||||
set -e
|
||||
|
||||
TIMESTAMP=$(date +"%Y-%m-%d %H:%M")
|
||||
LOG_FILE="/tmp/openclaw-backup.log"
|
||||
|
||||
echo "🔄 Starting OpenClaw backup... [$TIMESTAMP]" | tee -a "$LOG_FILE"
|
||||
|
||||
# GitTea credentials (stored in environment or config)
|
||||
# For automated backups, credentials should be configured in ~/.git-credentials
|
||||
# or use SSH keys
|
||||
|
||||
# Check if git credentials are configured
|
||||
if ! git config --global credential.helper &>/dev/null; then
|
||||
echo "⚠️ Warning: Git credential helper not configured" | tee -a "$LOG_FILE"
|
||||
echo " Run: git config --global credential.helper store" | tee -a "$LOG_FILE"
|
||||
fi
|
||||
|
||||
# Function to backup a repo
|
||||
backup_repo() {
|
||||
local path=$1
|
||||
local name=$2
|
||||
|
||||
cd "$path"
|
||||
|
||||
# Check if there are changes
|
||||
if [[ -n $(git status --porcelain) ]]; then
|
||||
echo "📦 $name: Changes detected, committing..." | tee -a "$LOG_FILE"
|
||||
git add -A
|
||||
git commit -m "Auto backup: $TIMESTAMP" || echo "⚠️ Commit failed or nothing to commit"
|
||||
|
||||
echo "☁️ $name: Pushing to GitTea..." | tee -a "$LOG_FILE"
|
||||
if git push origin master 2>&1 | tee -a "$LOG_FILE"; then
|
||||
echo "✅ $name: Backup successful" | tee -a "$LOG_FILE"
|
||||
else
|
||||
echo "❌ $name: Push failed - check credentials" | tee -a "$LOG_FILE"
|
||||
echo " To fix: git config --global credential.helper store" | tee -a "$LOG_FILE"
|
||||
echo " Then: cd $path && git push (enter credentials once)" | tee -a "$LOG_FILE"
|
||||
fi
|
||||
else
|
||||
echo "⏭️ $name: No changes to backup" | tee -a "$LOG_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
# Backup workspace
|
||||
echo "📂 Backing up workspace..." | tee -a "$LOG_FILE"
|
||||
backup_repo "/home/openclaw/.openclaw/workspace" "workspace"
|
||||
|
||||
echo "" | tee -a "$LOG_FILE"
|
||||
echo "✅ Backup process complete!" | tee -a "$LOG_FILE"
|
||||
echo "📄 Log saved to: $LOG_FILE" | tee -a "$LOG_FILE"
|
||||
|
||||
# Show recent backups
|
||||
echo "" | tee -a "$LOG_FILE"
|
||||
echo "📊 Recent backups:" | tee -a "$LOG_FILE"
|
||||
cd /home/openclaw/.openclaw/workspace && git log --oneline -3 | tee -a "$LOG_FILE"
|
||||
Reference in New Issue
Block a user