# Cron Job Examples for BC Backup Automation # Add these to your crontab with: crontab -e # =================================== # RECOMMENDED: Incremental + Full + Cleanup # =================================== # 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. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin # Incremental backup every 15 minutes */15 * * * * /root/BC-bak/bc-backup.sh --mode incremental >> /root/BC-bak/logs/cron.log 2>&1 # 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 # 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 # =================================== # Alternative: Incremental every 30 minutes # =================================== # */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 # =================================== # Alternative: Incremental hourly # =================================== # 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 # =================================== # Full backup only (no incremental) # =================================== # 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 # =================================== # With email notifications on failure # =================================== # MAILTO=admin@example.com # */15 * * * * /root/BC-bak/bc-backup.sh --mode incremental >> /root/BC-bak/logs/cron.log 2>&1 # =================================== # Systemd Timer Alternative # =================================== # Create /etc/systemd/system/bc-backup-incremental.service: # [Unit] # Description=BC Incremental Backup # # [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 # # Create /etc/systemd/system/bc-backup-incremental.timer: # [Unit] # Description=Run BC Incremental Backup Every 15 Minutes # # [Timer] # OnCalendar=*:0/15 # Persistent=true # # [Install] # WantedBy=timers.target # # Create similar for full backup (OnCalendar=*-*-* 02:00:00) # and cleanup (OnCalendar=*-*-* 03:00:00) # # Enable with: # sudo systemctl daemon-reload # sudo systemctl enable --now bc-backup-incremental.timer # =================================== # Useful Commands # =================================== # 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