One: Sub-library backup [[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=/optmyuser=rootmypass=666888socket=/data/3307/ mysql.sockmycmd= "mysql -u$myuser -p$mypass -s $SOCKET" mydump= "Mysqldump -u$myuser -p$MYPASS -S $SOCKET -x -b -f -r "[ ! -d $BAKPATH ] && madir -p /optdblist= ' $MYCMD -e "show databases;" | egrep -vi "Data|infor|mysql|perfor" ' for n in $DBLISTdo $MYDUMP $n |gzip > $BAKPATH/${n}_$ (date +%f). Sql.gz done II: Backing up the database [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=666888mysqlusr=root#must use root userrun scriptsif [ $UID -ne 0 ] ;then echo this script must use the root user ! !! sleep 2 exit 0fi#Define DIR andmkdir dirif [ ! -d $BAKDIR ]; then mkdir -p $ bakdirelse echo this is , $BAKDIR exists....fi#Use mysqldumpbackup mysqlfor 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.gzdone#/ application/mysql/bin/mysqldump -u$mysqlusr -p$mysqlpw -b# $MYSQLDB > $BAKDIR/mysql_ db.sql echo "The mysql backup successfully"
This article from "Randolph" blog, reproduced please contact the author!
MySQL Backup (i)