备份服务与定时器
备份服务与定时器
# /etc/systemd/system/backup.service
[Unit]
Description=nightly backup
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
# /etc/systemd/system/backup.timer
[Unit]
Description=run backup daily
[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true
RandomizedDelaySec=300
[Install]
WantedBy=timers.target启用与查看
启用与查看
systemctl daemon-reload
systemctl enable --now backup.timer
systemctl list-timers --all | grep backup
journalctl -u backup.service --since todayPersistent=true 让错过的任务在下次开机后补跑,适合与备份窗口配合使用。