How to Back Up Crontab List Automatically on Linux Servers?


On Linux OS, the crontab is a job list that comprises the list of tasks to do at a specified interval, e.g. daily, hourly, monthly etc. You can edit the list by crontab -e and print the list by command crontab -l.

It is text-based and each line is a job if not started by comment symbol #. If you have a large list and you might need to backup from time to time especially if you want to migrate between servers.

We can use the following command to do a backup on the list and save a copy each day so you can see historical copies.

crontab -l > /var/www/crontab/$(date +%Y-%m-%d) 2>&1

Of course, you can specify the directory for files to save and the example given above saves backups to folder /var/www/crontab. The $() is used to capture the output of any linux command which is used to wrap the date then we can obtain filenames such as 2015-03-19.

Finally put this line to crontab -e and specify the time interval to once per day like this.

22 0 * * * crontab -l >  /var/www/crontab/$(date +%Y-%m-%d) 2>&1

Alternatively,

@daily crontab -l >  /var/www/crontab/$(date +%Y-%m-%d) 2>&1

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
282 words
Last Post: How to Get Host Root Domain URL in PHP?
Next Post: Adsense 8 Years - Statistics!

The Permanent URL is: How to Back Up Crontab List Automatically on Linux Servers?

Leave a Reply