mysql 备份库的shell_linux备份Mysql数据库shell

欢迎拍砖,详细内容如下:

# 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  www.2cto.com

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

小编推荐:欲学习电脑技术、系统维护、网络管理、编程开发和安全攻防等高端IT技术,请 点击这里注册账号,公开课频道价值万元IT培训教程免费学,让您少走弯路、事半功倍,好工作升职加薪!

免责声明:本站系公益性非盈利IT技术普及网,本文由投稿者转载自互联网的公开文章,文末均已注明出处,其内容和图片版权归原网站或作者所有,文中所述不代表本站观点,若有无意侵权或转载不当之处请从网站右下角联系我们处理,谢谢合作!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值