HouYing

软件设计师-“夜深人静之时,头发斑白的老程序员会蜷缩在床上,欣赏一段精彩的子程序,或者苦思冥想一个绝妙的宏结构;而那些年少轻狂的程序员,则可能正在通过终端与别人聊得不亦乐乎。”...

实现自动备份表从源库到目标库

#!/bin/bash
user=root
pass=123456
dbFrom=mail
dbTo=analy
echo -e "==================backup old file start====================="
tar -czvf /root/backup/old_files/`date +%F`.tar.gz /root/backup/tables/*
rm -rf /root/backup/tables/*
echo -e "==================backup old file end====================="






echo -e "==================backup start====================="
tables=`mysql -u$user -p"$pass" -e "use $dbFrom;show tables;"|sed 1d`
cat tableName.txt | while read tableName
do
mysqldump -u$user -p"$pass"   -B --databases $dbFrom --tables $tableName > /root/backup/tables/${tableName}-`date +%F`.sql
[ $? -eq 0 ] && echo  $tableName ok >>/root/backup/table.log||echo $tableName failed >>/root/backup/table.log
[ $? -eq 0 ] && echo -e "$tableName ok" ||echo -e "$tableName failed"
done
echo -e "===================backup stop======================="




echo -e "==================import start====================="
for file in /root/backup/tables/*
do
    if test -f $file
    then
        echo import $file 
mysql -u$user -p$pass $dbTo < $file
    else
        echo $file is folder
    fi
done
echo -e "===================import stop======================="
 

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zwhfyy/article/details/78115620
个人分类: MySql
上一篇Mysql修改root用户密码
下一篇mysql 定时备份数据库脚本
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭