Home > Database > Mysql Tutorial > linux备份Mysql数据库shell_MySQL

linux备份Mysql数据库shell_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:42:50
Original
951 people have browsed it

bitsCN.com
欢迎拍砖,详细内容如下:  # MYSQL 数据文件路径 MYSQL_DATA_PATH="/usr/local/mysql/data/"  # 备份目录 MYSQL_DUMP_PATH="***/DB/"  # 备份用户名 MYSQL_ACCOUNT="mysql_backup"  # 备份密码 MYSQL_PASSWORD="mysql_backup"  MYSQLDUMP_OPTS="mysqldump -u$MYSQL_ACCOUNT -p$MYSQL_PASSWORD --single-transaction"  # 压缩命令  bzip2 -k 保留源文件 TAR_OPTS="bzip2 "  # 单个数据库进行备份 function BackDB(){         FULLPATH="$1"          #遍历目录         for dbName in $(/bin/ls $FULLPATH)         do                 # check is database                 fileType=`/usr/bin/file $FULLPATH$dbName | /bin/awk '{FS=":"} {printf $2}'`                  # 文件夹的类型为directory                 if [ "directory" == $fileType ]; then                         # start dump                         if [ "$dbName" == "mysql" ] /                                 || [ "$dbName" == "test" ] /                                 || [ "$dbName" == "information_schema" ] /                                 || [ "$dbName" == "performance_schema" ]; then                                 echo "------------->$dbName not need dump!!"                         else                                 echo $dbName                                   dumpName=$MYSQL_DUMP_PATH/"$dbName"_"$DATESTR"                                 $MYSQLDUMP_OPTS $dbName > "$dumpName".sql                                  # 压缩备份档                                 $TAR_OPTS "$BACKUP_NAME".sql                         fi                 else                         printf '%s is not database            ######## /n' $dbName                 fi         done }  # 每个数据表单独备份 function BackDBTB(){         FULLPATH="$1"          #遍历目录         for fName in $(/usr/bin/find $FULLPATH -name "*.ibd")         do                 dbPath=`echo "$fName" | /bin/awk 'BEGIN {FS="'$FULLPATH'"} {printf $2}'`                 # get database name                 dbName=`echo "$dbPath" | /bin/awk 'BEGIN {FS="/"} {printf $1}'`                 # get table name                 tbName=`echo "$dbPath" | /bin/awk 'BEGIN {FS="/"} {printf $2}'`                  # start dump                 if [ "$dbName" == "mysql" ]/                         || [ "$dbName" == "test" ] /                         || [ "$dbName" == "information_schema" ] /                         || [ "$dbName" == "performance_schema" ]; then                         echo "------------->$dbName not need dump!!"                 else                         echo $dbName $tbName                           dumpName=$MYSQL_DUMP_PATH/"$dbName"_"$tbName"_"$DATESTR"                         $MYSQLDUMP_OPTS $dbName $tbName > "$dumpName".sql                          # 压缩备份档                         $TAR_OPTS "$dumpName".sql                 fi         done }     作者 babaoqi bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template