-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_auto_backup.sh
More file actions
executable file
·91 lines (72 loc) · 2.53 KB
/
Copy pathsetup_auto_backup.sh
File metadata and controls
executable file
·91 lines (72 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# Setup automatic hourly backups for brain system
echo "🔄 Setting up automatic hourly backups..."
BRAIN_DIR="/Users/$(whoami)/brain-poc"
# Create the cron script
cat > "$BRAIN_DIR/cron_backup.sh" << 'EOF'
#!/bin/bash
# Brain system hourly backup
# This runs every hour to commit and push changes
BRAIN_DIR="/Users/$(whoami)/brain-poc"
cd "$BRAIN_DIR"
# Run auto-commit
/usr/bin/python3 "$BRAIN_DIR/auto_commit.py" check >> "$BRAIN_DIR/backup.log" 2>&1
# Log the action
echo "[$(date)] Auto-backup check completed" >> "$BRAIN_DIR/backup.log"
# Keep log file size manageable (last 100 lines)
tail -100 "$BRAIN_DIR/backup.log" > "$BRAIN_DIR/backup.log.tmp"
mv "$BRAIN_DIR/backup.log.tmp" "$BRAIN_DIR/backup.log"
EOF
chmod +x "$BRAIN_DIR/cron_backup.sh"
# Check if cron job already exists
if crontab -l 2>/dev/null | grep -q "cron_backup.sh"; then
echo "✅ Cron job already exists"
else
# Add to crontab (every hour at minute 0)
(crontab -l 2>/dev/null; echo "0 * * * * $BRAIN_DIR/cron_backup.sh") | crontab -
echo "✅ Cron job added for hourly backups"
fi
# Create launchd alternative for macOS (more reliable)
PLIST_FILE="$HOME/Library/LaunchAgents/com.brain.autobackup.plist"
cat > "$PLIST_FILE" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.brain.autobackup</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python3</string>
<string>$BRAIN_DIR/auto_commit.py</string>
<string>check</string>
</array>
<key>StartInterval</key>
<integer>3600</integer> <!-- Run every hour (3600 seconds) -->
<key>WorkingDirectory</key>
<string>$BRAIN_DIR</string>
<key>StandardOutPath</key>
<string>$BRAIN_DIR/backup.log</string>
<key>StandardErrorPath</key>
<string>$BRAIN_DIR/backup_error.log</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOF
# Load the launch agent
launchctl unload "$PLIST_FILE" 2>/dev/null
launchctl load "$PLIST_FILE"
echo "✅ LaunchAgent created for macOS"
echo ""
echo "🎯 Automatic backups configured:"
echo " - Every hour at :00"
echo " - Commits and pushes changes to GitHub"
echo " - Logs saved to: $BRAIN_DIR/backup.log"
echo ""
echo "📊 Check backup status with: bgit"
echo "💾 Force backup with: bbackup"
echo ""
echo "To disable:"
echo " Cron: crontab -e (remove the line)"
echo " LaunchAgent: launchctl unload $PLIST_FILE"