文档章节

backup mysql database

xxjbs001
 xxjbs001
发布于 2015/04/25 17:16
字数 175
阅读 6
收藏 0

#DataBase vars
DB_NAME_LIST=(xxxxx xxxxx xxxxx xxxx)  
DB_USER=""  
DB_PASS=""  
DB_HOST=""

#FTP vars
FTP_UPLOAD_DIR="/QA/mysql_backup"
FTP_HOST="172.16.10.241"
FTP_USER="xxxxxxx"
FTP_PASS="xxxxxxxx"

# Others vars  
# whereis mysqldump  
# IS ` but not '  
BIN_DIR="/usr/bin"  
BCK_DIR="/home/robot/mysql_backup"  
DATE=`date +%Y%m%d_%H%M%S`  

echo "Make a folder:" $DATE

mkdir $BCK_DIR/$DATE


for DB_NAME in ${DB_NAME_LIST[@]}
do

    echo "Backup DataBase:" $DB_NAME
    # TODO Backup MySQL  
    #$BIN_DIR/mysqldump --opt -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME  > $BCK_DIR/$DATE/$DB_HOST.$DB_NAME.dump.sql
    $BIN_DIR/mysqldump --defaults-extra-file=/etc/mysql/backup.cnf $DB_NAME > $BCK_DIR/$DATE/$DB_HOST.$DB_NAME.dump.sql
    #$BIN_DIR/mysqldump    --login-path=local -e $DB_NAME > $BCK_DIR/$DATE/$DB_HOST.$DB_NAME.dump.sql
    echo "Finish Backup DataBase:" $DB_NAME

done
    
# TODO tar .sql
echo "#################################################################"
echo "TAR the bakup folder"
echo "#################################################################"
tar -czvf $BCK_DIR/$DATE.tar.gz $BCK_DIR/$DATE

# TODO Upgrade MySQL Backup to FTP

echo "#################################################################"
echo "Upgrade MySQL Backup to FTP"
echo "#################################################################"

ftp -v -n $FTP_HOST << EOF
user $FTP_USER $FTP_PASS
binary
hash
cd $FTP_UPLOAD_DIR
lcd $BCK_DIR
prompt
put $DATE.tar.gz
bye
EOF

# TOD remove Backup file and folder

echo "Remove the backup folder and file " $DATE "and" $DATE.tar.gz

rm -rf *$DATE*



© 著作权归作者所有

共有 人打赏支持
xxjbs001
粉丝 55
博文 749
码字总数 215621
作品 0
浦东
QA/测试工程师
私信 提问
MySQL Backup and Restore Commands for DBA

MySQL Backup and Restore Commands for Database Administration by Ravi Saive | Published: November 2, 2012 | Last Updated: January 3, 2015 Download Your Free eBooks NOW - 10 Free......

rootliu
06/27
0
0
How to Back Up and Restore a MySQL Database

Reference: http://webcheatsheet.com/sql/mysqlbackuprestore.php If you're storing anything in MySQL databases that you do not want to lose, it is very important to make regular b......

perfectspr
2014/11/05
0
0
MySQL数据库备份的10个教程

MySQL 是用于交互式网站开发的最为知名的开源数据库系统。如果你使用的 MySQL 数据库,你应当经常有规律地备份数据,以防数据丢失(译注:不管用什么类型的数据都得定期备份)。这里有10个自...

Neo_
2012/03/27
0
0
MySQL Commands With Examples

The following MySQL Commands were originally split into several smaller blog posts that I had built up over the years, I have now consolidated the articles into a single post (f......

Ericklee
2015/03/05
0
0
CentOS 7 MySQL5.6分库分表-全备-shell脚本

#改改变量就可以了使用,所以输出信息自动生成mysql_backup.log日志,可查看脚本备份的时间, CentOS 7 MySQL自动备份shell脚本 系统环境: CentOS7 64位 MySQL-5.6 原理与工具: shell脚本 ...

amunlinux
08/03
0
0

没有更多内容

加载失败,请刷新页面

加载更多

Spring源码学习笔记-1-Resource

打算补下基础,学习下Spring源码,参考书籍是《Spring源码深度解析》,使用版本是Spring 3.2.x,本来想试图用脑图记录的,发现代码部分不好贴,还是作罢,这里只大略记录下想法,不写太细了 ...

zypy333
今天
10
0
RestClientUtil和ConfigRestClientUtil区别说明

RestClientUtil directly executes the DSL defined in the code. ConfigRestClientUtil gets the DSL defined in the configuration file by the DSL name and executes it. RestClientUtil......

bboss
今天
17
0

中国龙-扬科
昨天
2
0
Linux系统设置全局的默认网络代理

更改全局配置文件/etc/profile all_proxy="all_proxy=socks://rahowviahva.ml:80/"ftp_proxy="ftp_proxy=http://rahowviahva.ml:80/"http_proxy="http_proxy=http://rahowviahva.ml:80/"......

临江仙卜算子
昨天
10
0
java框架学习日志-6(bean作用域和自动装配)

本章补充bean的作用域和自动装配 bean作用域 之前提到可以用scope来设置单例模式 <bean id="type" class="cn.dota2.tpye.Type" scope="singleton"></bean> 除此之外还有几种用法 singleton:......

白话
昨天
10
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部