#!/bin/bash DBUSER=root DBPASSWD=123456 DBBAK1=mysql_test BACKUPDIR1=/data/backup_v2/mysql_test BACKTIME=`date +%Y%m%d%H%M%S` if [ ! -d $BACKUPDIR1 ];then mkdir $BACKUPDIR1 fi echo "==========$BACKTIME 数据库$DBBAK1备份开始==========" >> $BACKUPDIR1/mysql_test.log cd $BACKUPDIR1 mysqldump --opt -R --triggers -E --lock-all-tables --flush-logs --master-data=2 -u$DBUSER -p$DBPASSWD --databases $DBBAK1 > $DBBAK1.$BACKTIME.sql 2>> $BACKUPDIR1/mysql_test.log if [ $?==0 ];then tar zcf $DBBAK1.$BACKTIME.tar.gz $DBBAK1.$BACKTIME.sql > /dev/null rm -f $BACKUPDIR1/$DBBAK1.$BACKTIME.sql echo -e "=========数据库$DBBAK1 备份成功!!=========\n" >> $BACKUPDIR1/mysql_test.log else echo -e "=========数据库$DBBAK1 备份失败!!=========\n" >> $BACKUPDIR1/mysql_test.log fi find /data/backup_v2/mysql_test/ -mtime +10 -delete
本文出自 “激情燃烧的岁月” 博客,请务必保留此出处http://liuzhengwei521.blog.51cto.com/4855442/1909887
原文地址:http://liuzhengwei521.blog.51cto.com/4855442/1909887