mysql分库.分表备份
1.mysql的分库备份
myuser=root
mypass=yzg1314520
mycmd="mysql -u$myuser -p$mypass "
mydump="mysqldump -u$myuser -p$mypass"
for database in mysql test
do
$mydump $database > $database_$(date +%F).sql
tar -zcvf $database_$(date +%F).tar.gz $database_$(date +%F).sql
rm -rf $database_$(date +%F).sql
done
2.mysql的分库分表备份
myuser=root
mypass=yzg1314520
mycmd="mysql -u$myuser -p$mypass "
mydump="mysqldump -u$myuser -p$mypass"
for database in `$mycmd -e "show databases" | sed ‘1,3d‘`
do
mkdir -p /home/scripts/mysqlbak
for table in `$mycmd -e "show tables from $database;" |sed ‘1d‘`
do
$mydump $database $table > ${database}_${table}_$(date +%F).sql
tar -zcvf ${database}_${table}_$(date +%F).tar.gz ${database}_${table}_$(date +%F)
.sql
mv ./${database}_${table}_$(date +%F).tar.gz /home/scripts/mysqlbak
rm -rf /home/scripts/${database}_${table}_$(date +%F).sql
rm -rf $(find /home/scripts/mysqlbak -name "*.tar.gz" -mtime +5 -type f)
done
done
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。