一:分库备份 [[email protected] scripts]#cat mysql_fenku_bak.sh #!/bin/sh #-------------------------------------------- #Author: Created by randolph 2016-04 #Blog:http://randolph.blog.51cto.com #Function: This scripts function is MySQL Backup #Version:4.1.2 #--------------------------------------------- BAKPATH=/opt MYUSER=root MYPASS=666888 SOCKET=/data/3307/mysql.sock MYCMD="mysql -u$MYUSER -p$MYPASS -S $SOCKET" MYDUMP="mysqldump -u$MYUSER -p$MYPASS -S $SOCKET -x -B -F -R" [ ! -d $BAKPATH ] && madir -p /opt DBLIST=`$MYCMD -e "show databases;"|egrep -vi "data|infor|mysql|perfor"` for n in $DBLIST do $MYDUMP $n|gzip >$BAKPATH/${n}_$(date +%F).sql.gz done 二:备份数据库 [[email protected] scripts]#cat /server/scripts/Mysql_back.sh #!/bin/sh #-------------------------------------------- #Author: Created by randolph 2016-04 #Blog:http://randolph.blog.51cto.com #Function: This scripts function is MySQL Backup #Version:4.1.2 #--------------------------------------------- #Define PATH BAKDIR=/opt/bak_1/`date+%Y-%m-%d` #MYSQLDB=`mysql-uroot -p‘666888‘ -e "show databases;"|grep -Evi"data|infor|mys|per"` MYSQLPW=666888 MYSQLUSR=root #must use root userrun scripts if [ $UID -ne 0 ] ;then echo This script must use the root user ! !! sleep 2 exit 0 fi #Define DIR andmkdir DIR if [ ! -d $BAKDIR ]; then mkdir -p $BAKDIR else echo This is $BAKDIR exists.... fi #Use mysqldumpbackup mysql for dbname in `mysql -uroot -p‘888888‘ -e "show databases;"|grep -Evi"data|infor|mys|per"` do /application/mysql/bin/mysqldump -u$MYSQLUSR-p‘888888‘ --events -B $dbname|gzip >/opt/bak_1/${dbname}_bak.gz done #/application/mysql/bin/mysqldump -u$MYSQLUSR -p$MYSQLPW -B #$MYSQLDB>$BAKDIR/mysql_db.sql echo "The mysql backup successfully"
时间: 2024-10-14 11:11:13