Bash: Backup and restore of crontab

2012-09-12 Bash

Crontab Backup

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:

crontab -l

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.



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.

crontab -l

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