55 lines
1.7 KiB
Plaintext
55 lines
1.7 KiB
Plaintext
|
|
# Cron 备份配置示例
|
||
|
|
# 使用方法: crontab -e 并添加以下行
|
||
|
|
|
||
|
|
# 环境变量设置
|
||
|
|
SHELL=/bin/bash
|
||
|
|
PATH=/usr/local/bin:/usr/bin:/bin
|
||
|
|
BACKUP_DIR=/opt/user-management/backups
|
||
|
|
DB_PATH=/opt/user-management/data/user_management.db
|
||
|
|
CONFIG_PATH=/opt/user-management/configs/config.yaml
|
||
|
|
RETENTION_DAYS=30
|
||
|
|
|
||
|
|
# ============================================
|
||
|
|
# 备份任务
|
||
|
|
# ============================================
|
||
|
|
|
||
|
|
# 每天凌晨 2:00 执行备份
|
||
|
|
0 2 * * * /opt/user-management/scripts/backup/backup.sh >> /var/log/backup.log 2>&1
|
||
|
|
|
||
|
|
# 每周日凌晨 3:00 执行完整备份(包含上传到远程存储)
|
||
|
|
0 3 * * 0 /opt/user-management/scripts/backup/backup.sh && \
|
||
|
|
scp /opt/user-management/backups/latest.tar.gz backup@remote-server:/backups/
|
||
|
|
|
||
|
|
# 每天下午 6:00 检查备份状态并发送报告
|
||
|
|
0 18 * * * /opt/user-management/scripts/backup/backup.sh --verify || \
|
||
|
|
echo "Backup verification failed" | mail -s "Backup Alert" admin@example.com
|
||
|
|
|
||
|
|
# ============================================
|
||
|
|
# 清理任务
|
||
|
|
# ============================================
|
||
|
|
|
||
|
|
# 每月 1 日凌晨 4:00 清理超过 90 天的备份
|
||
|
|
0 4 1 * * find /opt/user-management/backups -name "*.tar.gz" -mtime +90 -delete
|
||
|
|
|
||
|
|
# ============================================
|
||
|
|
# 监控任务
|
||
|
|
# ============================================
|
||
|
|
|
||
|
|
# 每 15 分钟检查服务健康状态
|
||
|
|
*/15 * * * * curl -sf http://localhost:8080/api/v1/health || \
|
||
|
|
echo "Service down at $(date)" | mail -s "Service Alert" admin@example.com
|
||
|
|
|
||
|
|
# ============================================
|
||
|
|
# 日志轮转配置 (/etc/logrotate.d/user-management)
|
||
|
|
# ============================================
|
||
|
|
|
||
|
|
/var/log/backup.log {
|
||
|
|
daily
|
||
|
|
rotate 7
|
||
|
|
compress
|
||
|
|
delaycompress
|
||
|
|
missingok
|
||
|
|
notifempty
|
||
|
|
create 644 root root
|
||
|
|
}
|