• Linux学习系列之MySQL备份


    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

    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
  • 相关阅读:
    【从0开始Tornado网站】主页登录和显示的最新文章
    2014阿里巴巴网上笔试题-文章3大标题-公共最长的字符串长度
    取消改变基本数据——应用备忘录模式
    Hibernate进化史-------Hibernate概要
    xcode 快捷键
    Android多画面幻灯片:ViewPager基础上,利用与PagerTabStrip出生缺陷(源代码)
    uva 11991
    创建与删除索引
    HDU1203_I NEED A OFFER!【01背包】
    Java面试宝典2013版(超长版)
  • 原文地址:https://www.cnblogs.com/chadiandianwenrou/p/6078324.html
Copyright © 2020-2023  润新知