Linux comes with a time-based job scheduler called cron. The scheduler is configured by a crontab file. This post gives instructions of how to backup and restore crontab file.
To backup the current crontab settings for current user, use the command below,
crontab -l > crontab_backup
In case you want to backup crontab settings for a different user, use the command below,
crontab –l -u USERNAME > crontab_`date +%Y-%m-%d`
Suppose the crontab backup file is named as crontab_backup, simply use the command below to restore from the file
In case we have multiple backup files, and we want to restore the latest backup file, the command below will work,
cat `ls -tr crontab-* | tail -1` | crontab -u USERNAME –
The command finds the latest backup file, cat it to standard output, and the crontab command installs the crontab file for user “USERNAME”. The “-“ specifies that crontab will install crontab file from the standard input, which has the content of the latest backup file in this case.