systemd timers are the recommended way to schedule backups on modern Linux systems. They provide better logging, dependency management, and monitoring than cron.
Create /etc/systemd/system/backups@.service:
[Unit]
Description=Run backup job %i
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backups /etc/backups/%i.json
User=root
StandardOutput=journal
StandardError=journal
SyslogIdentifier=backups-%iCreate /etc/systemd/system/backups@.timer:
[Unit]
Description=Scheduled backup job %i
[Timer]
OnCalendar=*-*-* 03:00:00
RandomizedDelaySec=300
Persistent=true
[Install]
WantedBy=timers.target# Enable and start a timer for a specific config file (e.g. /etc/backups/production.json)
systemctl enable --now backups@production.timer
# Check status
systemctl status backups@production.timer
systemctl status backups@production.service
# View logs
journalctl -u backups@production.service -fThe @ (template) unit lets you run multiple backup jobs from one pair of unit files, one per config file.
If you need different schedules per job, create separate timer overrides:
systemctl edit backups@offsite.timer[Timer]
OnCalendar=
OnCalendar=*-*-* 01:00:00Add an entry to /etc/cron.d/backups:
# Run backups daily at 3am
0 3 * * * root /usr/local/bin/backups /etc/backups/production.json >> /var/log/backups.log 2>&1Or using crontab -e for the root user:
0 3 * * * /usr/local/bin/backups /etc/backups/production.jsonPair the backup job with the flag file notification for simple freshness monitoring, or the Prometheus notification for metrics-based alerting.