在 Debian(及其他 Linux 发行版)里,“定时器”通常指 systemd 定时器(systemd timer),也可能指 cron 任务。下面分别说明如何迁移。
systemctl list-timers --all
查看某个定时器文件位置:
systemctl cat mytimer.timer
systemctl cat mytimer.service
systemd 定时器通常由两个文件组成:
.timer 文件.service 文件(被 timer 调用)常见位置:
/etc/systemd/system/
/lib/systemd/system/
/usr/lib/systemd/system/
备份示例:
cp /etc/systemd/system/mytimer.timer /backup/
cp /etc/systemd/system/mytimer.service /backup/
将文件复制到新机器的相同路径:
scp mytimer.timer mytimer.service root@newhost:/etc/systemd/system/
systemctl daemon-reload
systemctl enable --now mytimer.timer
systemctl status mytimer.timer
systemctl list-timers
crontab -l
ls /etc/cron.d/
cat /etc/cron.d/*
用户 cron:
crontab -l > cron.backup
系统 cron:
tar czf cron-system.tar.gz /etc/cron.d /etc/crontab
用户 cron:
crontab cron.backup
系统 cron:
tar xzf cron-system.tar.gz -C /
cron 环境极少,建议:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
journalctl -u mytimer.service
journalctl -u mytimer.timer
--now如果你能提供:
我可以给你更精确的迁移步骤。