If you use cron quite often, it is a good practice to backup it from time to time. This can be achieved in a very easy way. First, see what is your crontab content:
Now just redirect standard output from screen to the destination file – our backup.
crontab -l > /cron_`date '+%F_%T' | sed -e 's/:/_/g'`
This command will create a dump with the name that contains date and time of it’s creation.
cron_2012-09-10_14_54_01 cron_2012-09-11_14_54_26 cron_2012-09-12_14_55_28
If you want to restore it, the only thing you have to do is to override it with backup content. Cron’s content (individual for every user) is located in:
So let’s override it for root account:
cp cron_2012-09-12_14_55_28 /var/spool/cron/crontabs/root
To make sure that override process was correct browse it once again.
You should see new entries. To make sure write them and exit.
You should see a confirmation quite similar to this below.
crontab: installing new crontab