MySQL Database backup script

Source: Internet
Author: User

MySQL backup script


#!/bin/bash ## author: liwenlong ## 2015 December 29 ## description:  backup file, smart child row card database backup ######### ###### #数据库备份脚本 ####################### user=backup       # #数据库连接用户 PASSWD= "* * * "          # #数据库连接密码 database=" test test3  Test4 " # #数据库名, if you want to add a database to be backed up, hostname=" 192.168.1.47 "     # #服务器IP地址 port=" 3306 "       # #数据库端口     backup_dir=/home/backup/mysql_backup/        # #备份目录 option= "  -h$HOSTNAME -P  $PORT  -u$ user -p$passwd   "    time= ' date +%f-%h:%m:%s '      # #年月日时分秒 backup_log_file=/var/log/mysql_backup.log   # #日志文件, create delete_log_file=/var/log/mysql_ manually delete.log   # #日志文件, manually create ###################################################### ################# #创建数据库备Catalogue ################## for i in  $DATABASE  ; do # #如果目录不存在, creating directories   if [  ! -d  $BACKUP _dir$i ] ; then mkdir  -p  $BACKUP _dir$i fi done ############## ########### #备份数据库 ################## for i in  $DATABASE  ; do mysqldump  $OPTION    $i  | bzip2 -c    >  $BACKUP _dir$i/$i-$TIME. sql.bz2 if  [[ $? == 0 ]]; then  #如果数据库备份成功, write log file; echo  "  $BACKUP _dir$i  backup successful!  $TIME " >>  $BACKUP _log_file  else # #否则写入错误日志文件; echo 
"  $BACKUP _dir$i backup fail...  $TIME  "   >>  $BACKUP _log_file fi Done ########## #删除一个月之前的备份文件 ######################## for i in  $DATABASE  ; do find $ Backup_dir$i/ -mtime +3 -type f | xargs rm -f if [[ $? = =&nBsp;0 ]]; then         # #删除一个月前的数据库, writing log files                    echo  "  $BACKUP _ dir$i delete  successful!  $TIME " >>  $DELETE _log_file          else                  echo  "  $BACKUP _dir$i delete   fail...  $TIME  "   >>  $DELETE _log_file         fi Done


This article is from the "obsessed" blog, make sure to keep this source http://dragondragon.blog.51cto.com/6170889/1729577

MySQL Database backup script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.