backup mysql database
博客专区 > xxjbs001 的博客 > 博客详情
backup mysql database
xxjbs001 发表于3年前
backup mysql database
  • 发表于 3年前
  • 阅读 4
  • 收藏 0
  • 点赞 0
  • 评论 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*



共有 人打赏支持
粉丝 53
博文 297
码字总数 215619
×
xxjbs001
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: