writelog()
{
if [ $2 -eq 0 ]; then
echo $1 " ...... backup Sucess." >> $log
else
echo $1 " ..... backup Faild." >> $log
mail -s "$1 Backup faild on Mail Server." $recipient
# $SENDM
exit 1
fi;
}
# MySQL DUMP TO temp File /tmp/tempfilename
# tar tempfile to mysql.$f1.date.tar.gz
echo "Start Backuping...." > $log
echo "$datef "`date +%T` >> $log
echo "------------------------" >> $log
$command -u$myuser -p$mypasswd $mydatabase > $tempfilename
writelog "mysql $1 ...." $?
cd tempfolder
$TAR czf $tempfolder/$filename $tempfilename
writelog "Tar...." $?
#
#判断/mnt/0.16这个目录是否已经被mount了。
count=`mount |grep "$dest_dir" |wc -l`
if [ $count -eq 0 ]; then
mount -o username=$nsuser,password=$nspasswd $remoteshare $dest_dir
fi
writelog "Mount...." $?
#
# Move Mysql Backup File to Network that is $remoteshare or /mnt/ip0.16
#
mv $tempfolder/$filename $dest_dir/$filename
writelog "move $filename to $dest_dir " $?
# Delete over days ago of $2
# 删除过期的文件。
if [ -f "$dest_dir/$overfilename" ]; then
rm -rf $dest_dir/$overfilename
writelog "$overfilename was deleted...." $?
fi;
umount $dest_dir
writelog "umount $dest_dir" $?
#把每天步的运行结果邮件出去。
mail -s "MySQL backup Complete for Mail Server.." $recipient<$log
#$SENDM
3、运行crontab -e做日程,或把前的的crontab例处的保存为文件放在cron.d中的day或weeks文件夹中。
MySQL邮件服务器数据库备份脚本(2)
内容版权声明:除非注明,否则皆为本站原创文章。