Getting started with MySQL regular data backup

Source: Internet
Author: User

If you are a beginner in the practical application of MySQL scheduled data backup and you are not familiar with the practical application of MySQL scheduled data backup, the following articles will provide you with more comprehensive knowledge. I hope it will help you in this regard.

You can rewrite it as needed :)
Run Java code

 
 
  1. bash MySQL_backup.sh   
  2. bash MySQL_backup.sh  

Java code

 

 
 
  1. #!/bin/bash   
  2. #This is a ShellScript For Auto DB Backup   
  3. #Powered by liuzheng  

System variable definition
 

 
 
  1. DBName=Bulletin_production   
  2. DBUser=root   
  3. DBPasswd=   
  4. BackupPath=/home/worker/MySQL_backup/   
  5. NewFile="$BackupPath"db$(date +%y%m%d).tar.gz   
  6. DumpFile="$BackupPath"db$(date +%y%m%d).sql   
  7. OldFile="$BackupPath"db$(date +%y%m%d --date='1 days ago').tar.gz   

Create backup file
 

 
 
  1. if [ ! -d $BackupPath ]; then   
  2. mkdir $BackupPath   
  3. fi   
  4. echo "---------------------------"   
  5. echo $(date +"%y-%m-%d %H:%M:%S")   
  6. echo "---------------------------"   

Delete historical files from MySQL scheduled data backup
 

 
 
  1. if [ -f $OldFile ]; then   
  2. rm -f $OldFile >> $LogFile   
  3. echo "[$OldFile]Delete Old File Success!"   
  4. else   
  5. echo "not exist old file!"   
  6. fi   

New File
 

 
 
  1. if [ -f $NewFile ]; then   
  2. echo "[$NewFile] The Backup File is exists,Can't Backup! "   
  3. else   
  4. MySQLdump -u $DBUser $DBName > $DumpFile   
  5. tar czvf $NewFile $DumpFile   
  6. rm -rf $DumpFile   
  7. echo "[$NewFile]Backup Success!"   
  8. fi  

The above content is an introduction to MySQL regular data backup. I hope you will get some benefits.

Related Article

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.