shell编程基础-shell分库备份
Posted sunziying
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell编程基础-shell分库备份相关的知识,希望对你有一定的参考价值。
分库备份
企业实战题7:如何实现对mysql数据库进行分库备份,请用脚本实现
#!/bin/bash MysqlUser=root PassWord=root Port=3306 Socket="/usr/include/mysql/mysql.sock" MysqlCmd="mysql -u$MysqlUser -p$PassWord -S $Socket" Database=`$MysqlCmd -e "show databases;"|egrep -v "Database|_schema|mysql"` MysqlDump="mysqldump-u$MysqlUser -p$PassWord -S $Socket" IP=`ifconfig enp0s3|grep "broadcast"|awk ‘{print $NF}‘` //centos 7 BackupDir=/backup/$IP [ -d $BackupDir ] || mkdir -p$BackupDir for dbname in $Database do $MysqlDump --events -B $dbname|gzip>/$BackupDir/${dbname}_$(date +%F)_bak.sql.gz done
以上是关于shell编程基础-shell分库备份的主要内容,如果未能解决你的问题,请参考以下文章