mysql导出导入linux脚本sh
脚本示例:#!/bin/shfunction handle(){local begin_date=$1# local end_date=$2local end_date=`date -d "-1 days ago $2" +%Y%m%d`local outpath="/user/mysql_151_Data/conso...
·
脚本示例:
#!/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
说明:
更多推荐
已为社区贡献1条内容
所有评论(0)