mysql导出导入linux脚本sh

脚本示例:

#!/bin/sh
function handle(){

        local begin_date=$1
        # local end_date=$2
        local end_date=`date -d "-1 days ago $2" +%Y%m%d`

        local outpath="/user/mysql_151_Data/consolelog/info$(date "+%Y%m%d").log"

        echo $(date "+%Y-%m-%d %H:%M:%S")" start----" >> $outpath

        while [ "$begin_date" != "$end_date" ]
        do
                echo $begin_date
                echo $(date "+%Y-%m-%d %H:%M:%S")" t_mt_"$begin_date"----" >> $outpath
                # 数据导出
                mysqldump -h192.168.0.45 -utestuser -p123456  -Ddb_user t_mt_"$begin_date" > /user/mysql_151_Data/data/t_mt_"$begin_date".sql
                echo $(date "+%Y-%m-%d %H:%M:%S")" t_mt_"$begin_date"--export_end--" >> $outpath
                # 数据导入(本机导入)
                mysql -utestuser -p123456  -Ddb_user < /user/mysql_151_Data/data/t_mt_"$begin_date".sql
                echo $(date "+%Y-%m-%d %H:%M:%S")" t_mt_"$begin_date"--import_end--" >> $outpath


                begin_date=`date -d "-1 days ago ${begin_date}" +%Y%m%d`
        done
        echo "end:"$end_date

        echo $(date "+%Y-%m-%d %H:%M:%S")" end----" >> $outpath


}
# handle 后跟两个参数,分别是开始日期和结束日期
handle 20170929 20170929

说明:
在这里插入图片描述

发布了24 篇原创文章 · 获赞 50 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/u013015301/article/details/96984765