Wednesday, March 25, 2015

Backup cron jobs

If you have corn jobs in your server, below script helpful to take backup cronjobs details.



#!/bin/ksh
#
#   Keep a backup on crontab entries for 90 days
#
#- ENV VARIABLES -#

. ~oracle/.env
DATE=`date +%y%m%d`
CRONTAB_DIR=/u01/app/oracle/prod/
MACHINE=`hostname`
export DATE MACHINE

# Keep last 30  days of crontab entries
find $CRONTAB_DIR -name "crontab.*.txt" -mtime +30 -exec rm {} \;

crontab -l > $CRONTAB_DIR/crontab.$DATE.txt

if [[ $? -gt 0 ]];then
mail -s 'Error creating backup crontab on '$MACHINE'' $DBAEMAIL << EOF
Problems creating backup crontab. Check $CRONTAB_DIR for backup crontabs.
EOF
exit
fi

exit 0