首页 > 代码库 > MySQL备份
MySQL备份
1. MySQL排除表备份
#!/bin/bash #created by 90root #date: 20160809 date_y=$( date +%Y) date_m=$( date +%m) time =` date ‘+%F-%R‘ ` mysql_user= "mysql_user" mysql_passwd= "mysql_passwd" mysql_host= "127.0.0.1" tar_path= "/data/backup/backup_mysql_tables" mysql_dump= "mysqldump -h$mysql_host -u$mysql_user -p$mysql_passwd" mysql_cmd= "mysql -h$mysql_host -u$mysql_user -p$mysql_passwd" #备份数据库列表 backup_db_arr=( "test1" "test2" "test3" "test4" ) #测数据库存放路径 if [ ! -d $tar_path/$date_y/$date_m ]; then mkdir -p $tar_path/$date_y/$date_m fi #排除备份数据库列表 exclude_db_tables= "tables_name1|tables_name2|tables_name3|tables_name4" #循环数组 for j in "${backup_db_arr[@]}" ; do if [ "$j" == "test2" ]; then for i in `$mysql_cmd -e "use $j;show tables" | sed ‘1d‘ | grep -Ev "$exclude_db_tables" `; do $mysql_dump $j $i| gzip >> $tar_path/$date_y/$date_m/$j-$ time .sql.gz done else $mysql_dump $j | gzip >> $tar_path/$date_y/$date_m/$j-$ time .sql.gz fi done |
2. MySQL多库备份
#!/bin/bash #about: 90root date =$( date +%Y%m%d-%H:%M) date_y=$( date +%Y) date_m=$( date +%m) Mysql_Backup_Path= /data/backup/backup_mysql Mysql_host= "127.0.0.1" Mysql_user= "mysql_user" Mysql_pass= "mysql_passwd" Mysql_cmd= "mysql -h$Mysql_host -u$Mysql_user -p$Mysql_pass" Mysql_dump= "mysqldump -h$Mysql_host -u$Mysql_user -p$Mysql_pass" Mysql_database= "test1 test2 test3" #检测数据库存放路径 if [ ! -d $Mysql_Backup_Path/$date_d ]; then mkdir -p $Mysql_Backup_Path/$date_y/$date_m fi #清空mysql备份日志文件 echo > $Mysql_Backup_Path /mysqldump .log #判断日期目录 if [ ! -d $Mysql_Backup_Path/$date_y/$date_m ]; then mkdir $Mysql_Backup_Path/$date_y/$date_m fi #多库备份 for dbname in $Mysql_database; do $Mysql_dump $dbname | gzip > $Mysql_Backup_Path/$date_y/$date_m/${dbname}_${ date }.sql.gz if [ $? - eq 0 ]; then echo "****** mysqldump ${dbname} `date +%Y%m%d-%H:%M:%S` ******" >> $Mysql_Backup_Path /mysqldump .log fi done |
本文出自 “断肠人在天涯” 博客,请务必保留此出处http://8649605.blog.51cto.com/8639605/1855601
MySQL备份
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。