将 cron 作业从一台服务器复制到另一台服务器 - 优先使用 bash

将 cron 作业从一台服务器复制到另一台服务器 - 优先使用 bash

我最近从一台专用 centos 服务器迁移到了另一台专用 centos 服务器。我的旧服务器上运行着一些备份 cron 作业。我想将它们复制到新服务器上。有人能指导我吗?最好使用 bash。

答案1

Centos 使用 cronie,它从以下位置读取文件/crontab:

/etc/cron.d/ # Put any readable file here. Syntax example in /etc/crontab
/etc/cron.daily/ # Any root executable files here. runs daily
/etc/cron.deny # newline separated list of users to deny crontab. 
/etc/cron.hourly/ # Same setup as daily
/etc/cron.monthly/ # same setup as daily
/etc/crontab # Shell variables that all cron jobs source before running.
/etc/cron.weekly/ # same setup as daily 

/var/spool/cron/* # most user defined cron jobs are put here. 

答案2

您将必须或多或少地手动重新创建 cron 作业。

  • 将相关的 crontab 条目复制到新服务器上的 crontab。我通常只是借助工作机器的剪贴板和两个 ssh 会话进行复制和粘贴。
  • 如果文件在/etc/cron.d/etc/cron.daily等中,请将脚本从那里复制到新服务器
  • 确保您当前 cron 作业中引用的任何脚本、文件或其他资源在新服务器上可用。这些资源是什么完全取决于您的本地配置。

相关内容