You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.1 KiB
76 lines
2.1 KiB
#!/bin/bash |
|
############################################################################### |
|
# Install cron jobs for automated backup and memory cleanup. |
|
# |
|
# Cron schedule: |
|
# Daily 02:00 AM - Full backup (workspace + Qdrant snapshot + profiles) |
|
# Sunday 03:00 AM - Memory cleanup (delete expired session/chat_summary) |
|
# |
|
# Usage: |
|
# ./setup-cron.sh # install cron jobs |
|
# ./setup-cron.sh remove # remove OpenClaw cron jobs |
|
# ./setup-cron.sh status # show current OpenClaw cron entries |
|
############################################################################### |
|
|
|
set -e |
|
|
|
WORKSPACE="/root/.openclaw/workspace" |
|
MARKER="# openclaw-auto" |
|
DEPLOY="$WORKSPACE/deploy.sh" |
|
CLEANUP="python3 $WORKSPACE/skills/mem0-integration/memory_cleanup.py" |
|
LOG_DIR="$WORKSPACE/logs/system" |
|
|
|
install_cron() { |
|
mkdir -p "$LOG_DIR" |
|
|
|
local existing |
|
existing=$(crontab -l 2>/dev/null || true) |
|
|
|
if echo "$existing" | grep -q "$MARKER"; then |
|
echo "OpenClaw cron jobs already installed. Use '$0 remove' first to reinstall." |
|
echo "" |
|
show_status |
|
return |
|
fi |
|
|
|
local new_cron="$existing |
|
0 2 * * * $DEPLOY backup >> $LOG_DIR/cron-backup.log 2>&1 $MARKER |
|
0 3 * * 0 $CLEANUP --execute --max-age-days 90 >> $LOG_DIR/cron-cleanup.log 2>&1 $MARKER" |
|
|
|
echo "$new_cron" | crontab - |
|
echo "Cron jobs installed:" |
|
echo " Daily 02:00 - Full backup" |
|
echo " Sunday 03:00 - Memory cleanup (90-day max-age)" |
|
echo "" |
|
echo "Logs:" |
|
echo " $LOG_DIR/cron-backup.log" |
|
echo " $LOG_DIR/cron-cleanup.log" |
|
} |
|
|
|
remove_cron() { |
|
local existing |
|
existing=$(crontab -l 2>/dev/null || true) |
|
|
|
if ! echo "$existing" | grep -q "$MARKER"; then |
|
echo "No OpenClaw cron jobs found." |
|
return |
|
fi |
|
|
|
echo "$existing" | grep -v "$MARKER" | crontab - |
|
echo "OpenClaw cron jobs removed." |
|
} |
|
|
|
show_status() { |
|
echo "OpenClaw cron entries:" |
|
crontab -l 2>/dev/null | grep "$MARKER" || echo " (none)" |
|
} |
|
|
|
case "${1:-install}" in |
|
install) install_cron ;; |
|
remove) remove_cron ;; |
|
status) show_status ;; |
|
*) |
|
echo "Usage: $0 [install|remove|status]" |
|
exit 1 |
|
;; |
|
esac
|
|
|