Tuesday 27 May 2014

Crontab is lost !!!!,....... consider taking a backup before and after adding an entry or modifying the crontab ......... You may write a custom script which is automatically take the backup of crontab....... ( You may use the script below)


Note :
please use the script carefully before deploying in your server its advised to implement in test server 

Note : 
Implementing or trying any of the advice from this blog is at your own risk.



# Scripts Start
# This script will generate a crontab backup file and will email to mentioned ids
# Script Created Karthikeyan.K
# karthik-oracledba.blogspot.in
#================================================================================
#Below syntax will create a new file with present date with name specified.
START_DT=`date '+%d_%m_%Y'`
file_name=$HOME/cron_backup_$START_DT.txt

crontab -l > $file_name

/usr/bin/uuencode $file_name $file_name | mailx -s "The crontab backup of HOST(IP)" ____@__.com

# Below will delete 30 Days old crontab
find $HOME/cron_backup_*.txt -mtime +30 -exec rm {} \;

#### IMPORTANT THE ABOVE SYNTAX WILL DELETE ANY FILE IN HOME DIRECTORY WHICH HAS THE NAMING CONVENTION cron_backup_*.txt !!!!!!!!! 

#=================================================================================
# Scripts End








Tip : 
===

place all your cron job shell scripts in one directory this will help in taking a backup of script directory as well if possible direct this parent folder to tape backup

No comments:

Post a Comment