openclaw-home-pc/workspace/scripts/openclaw-backup-notify.sh
2026-03-21 15:31:06 +08:00

64 lines
2.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ============================================================================
# OpenClaw 备份通知脚本
# 功能:读取备份报告并通过企业微信发送给用户
# ============================================================================
# 读取报告文件
REPORT_FILE="$1"
if [ ! -f "$REPORT_FILE" ]; then
# 尝试查找最新的报告
REPORT_FILE=$(ls -t /tmp/openclaw_backup_report_*.txt 2>/dev/null | head -1)
fi
if [ ! -f "$REPORT_FILE" ]; then
echo "❌ 未找到备份报告文件"
exit 1
fi
# 提取关键信息
BACKUP_NAME=$(grep "备份文件:" "$REPORT_FILE" | cut -d: -f2 | tr -d ' ')
BACKUP_SIZE=$(grep "压缩包大小:" "$REPORT_FILE" | cut -d: -f2 | tr -d ' ')
MEMORY_COUNT=$(grep "记忆文件:" "$REPORT_FILE" | cut -d: -f2 | tr -d ' ')
SKILL_COUNT=$(grep "技能数量:" "$REPORT_FILE" | cut -d: -f2 | tr -d ' ')
TOTAL_BACKUPS=$(grep "总备份数:" "$REPORT_FILE" | cut -d: -f2 | tr -d ' ')
TOTAL_SIZE=$(grep "总占用:" "$REPORT_FILE" | cut -d: -f2 | tr -d ' ')
# 生成通知消息
MESSAGE="🦐 OpenClaw 备份完成报告
📅 备份时间:$(date '+%Y-%m-%d %H:%M:%S')
📦 备份文件:$BACKUP_NAME
💾 压缩包大小:$BACKUP_SIZE
📊 备份内容:
✅ 核心配置 (openclaw.json)
✅ 定时任务 (cron/)
✅ 设备身份 (identity/)
✅ 企业微信配置 (wecomConfig/)
✅ 凭证文件 (credentials/)
✅ 工作区 (workspace/)
- 记忆文件:$MEMORY_COUNT
- 自定义技能:$SKILL_COUNT
📋 备份统计:
• 总备份数:$TOTAL_BACKUPS
• 总占用:$TOTAL_SIZE
• 保留策略7 天
✅ 备份状态:成功
🧹 旧备份已清理"
# 通过 OpenClaw 发送消息
# 使用 sessions_send 发送到主会话
openclaw sessions send --session-key "agent:main:wecom:direct:houhuan" --message "$MESSAGE" 2>/dev/null
if [ $? -eq 0 ]; then
echo "✅ 通知已发送"
else
# 备用方案:直接输出消息
echo "💡 通知内容:"
echo "$MESSAGE"
fi