Script to take backup of Mails
The script was written to take the backup of the mails on weekly bases using cron. The script use to kill Thunderbird in my case and then start taking the backup so that no new mail comes in while the backup is in progress, a kind of cold backup.
#Script to take backup of Mails
#!/bin/bash
PID=`pidof thunderbird-bin`
LOC="/home/sawrub/.thunderbird/8vqt6zno.default/Mail/"
DAY=`date +%F`
REPORT="/tmp/Mail_REPORT"
echo -e "`date`: Starting Mail Backup" > ${REPORT}
echo -e "`date`: Going to Kill Thunderbird, PID : ${PID}" >> ${REPORT}
kill -9 $PID >> /dev/null
echo -e "`date`: Thunderbird Killed Successfuly" >> ${REPORT}
cd $LOC
FILE="Mail_${DAY}.tar.bz2"
echo -e "`date`: Backup Starts at `date +%R`" >> ${REPORT}
echo -e "`date`: The backup will be saved as ${FILE}" >> ${REPORT}
tar -cjpf /data/mails_backup/${FILE} *
su - sawrub -c thunderbird
echo -e "`date`: Backup Completes" >> ${REPORT}
sleep 5
echo -e "`date`: Thunderbird starts of successfully as PID :`pidof thunderbird-bin`" >> ${REPORT}
SIZE=`du -h /data/mails_backup/${FILE}|awk '{print $1}'`
echo -e "`date`: Backup size is ${SIZE}" >> ${REPORT}
mail sawrub -s"Mails Backed Up" < ${REPORT} sleep 2 rm -rf ${REPORT} #Delete the stale Mail backup Data
Comments
Post a Comment