Files
BC-bak/cron-examples.txt

93 lines
3.5 KiB
Plaintext
Raw Permalink Normal View History

2026-02-09 18:57:39 +01:00
# Cron Job Examples for BC Backup Automation
# Add these to your crontab with: crontab -e
# ===================================
# RECOMMENDED: Incremental + Full + Cleanup
2026-02-09 18:57:39 +01:00
# ===================================
# This is the recommended setup for production use:
# - Incremental every 15 minutes (only changed records)
# - Full backup daily at 2 AM (complete snapshot)
# - S3 cleanup daily at 3 AM (delete expired backups)
#
# The lock file prevents overlapping runs, so if a full backup
# is still running at :15, the incremental will skip gracefully.
2026-02-09 18:57:39 +01:00
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
2026-02-09 18:57:39 +01:00
# Incremental backup every 15 minutes
*/15 * * * * /root/BC-bak/bc-backup.sh --mode incremental >> /root/BC-bak/logs/cron.log 2>&1
2026-02-09 18:57:39 +01:00
# Full backup daily at 2:00 AM
0 2 * * * /root/BC-bak/bc-backup.sh --mode full >> /root/BC-bak/logs/cron.log 2>&1
2026-02-09 18:57:39 +01:00
# S3 cleanup daily at 3:00 AM (delete backups older than RETENTION_DAYS)
0 3 * * * /root/BC-bak/bc-cleanup.sh >> /root/BC-bak/logs/cron.log 2>&1
2026-02-09 18:57:39 +01:00
# ===================================
# Alternative: Incremental every 30 minutes
2026-02-09 18:57:39 +01:00
# ===================================
# */30 * * * * /root/BC-bak/bc-backup.sh --mode incremental >> /root/BC-bak/logs/cron.log 2>&1
# 0 2 * * * /root/BC-bak/bc-backup.sh --mode full >> /root/BC-bak/logs/cron.log 2>&1
# 0 3 * * * /root/BC-bak/bc-cleanup.sh >> /root/BC-bak/logs/cron.log 2>&1
2026-02-09 18:57:39 +01:00
# ===================================
# Alternative: Incremental hourly
2026-02-09 18:57:39 +01:00
# ===================================
# 0 * * * * /root/BC-bak/bc-backup.sh --mode incremental >> /root/BC-bak/logs/cron.log 2>&1
# 0 2 * * * /root/BC-bak/bc-backup.sh --mode full >> /root/BC-bak/logs/cron.log 2>&1
# 0 3 * * * /root/BC-bak/bc-cleanup.sh >> /root/BC-bak/logs/cron.log 2>&1
2026-02-09 18:57:39 +01:00
# ===================================
# Full backup only (no incremental)
2026-02-09 18:57:39 +01:00
# ===================================
# 0 2 * * * /root/BC-bak/bc-backup.sh --mode full >> /root/BC-bak/logs/cron.log 2>&1
# 0 3 * * * /root/BC-bak/bc-cleanup.sh >> /root/BC-bak/logs/cron.log 2>&1
2026-02-09 18:57:39 +01:00
# ===================================
# With email notifications on failure
2026-02-09 18:57:39 +01:00
# ===================================
# MAILTO=admin@example.com
# */15 * * * * /root/BC-bak/bc-backup.sh --mode incremental >> /root/BC-bak/logs/cron.log 2>&1
2026-02-09 18:57:39 +01:00
# ===================================
# Systemd Timer Alternative
2026-02-09 18:57:39 +01:00
# ===================================
# Create /etc/systemd/system/bc-backup-incremental.service:
2026-02-09 18:57:39 +01:00
# [Unit]
# Description=BC Incremental Backup
2026-02-09 18:57:39 +01:00
#
# [Service]
# Type=oneshot
# ExecStart=/root/BC-bak/bc-backup.sh --mode incremental
# StandardOutput=append:/root/BC-bak/logs/backup.log
# StandardError=append:/root/BC-bak/logs/backup.log
2026-02-09 18:57:39 +01:00
#
# Create /etc/systemd/system/bc-backup-incremental.timer:
2026-02-09 18:57:39 +01:00
# [Unit]
# Description=Run BC Incremental Backup Every 15 Minutes
2026-02-09 18:57:39 +01:00
#
# [Timer]
# OnCalendar=*:0/15
2026-02-09 18:57:39 +01:00
# Persistent=true
#
# [Install]
# WantedBy=timers.target
#
# Create similar for full backup (OnCalendar=*-*-* 02:00:00)
# and cleanup (OnCalendar=*-*-* 03:00:00)
#
2026-02-09 18:57:39 +01:00
# Enable with:
# sudo systemctl daemon-reload
# sudo systemctl enable --now bc-backup-incremental.timer
2026-02-09 18:57:39 +01:00
# ===================================
# Useful Commands
2026-02-09 18:57:39 +01:00
# ===================================
# Edit crontab: crontab -e
# List crontab: crontab -l
# View cron logs: grep CRON /var/log/syslog
# Manual full backup: /root/BC-bak/bc-backup.sh --mode full
# Manual incremental: /root/BC-bak/bc-backup.sh --mode incremental
# Manual cleanup: /root/BC-bak/bc-cleanup.sh
# Check backup state: cat /root/BC-bak/last-run-state.json