Creation after automatic backup failure in the MySQL database

Source: Internet
Author: User

This article mainly introduces the conditions required to create a database backup after the automatic backup in the MySQL database and the restoration after the MySQL database is damaged, including the creation of an automatic backup script, the MySQL database automatic backup script runs correctly and the database backup script runs automatically every day.

[1] creating an automatic backup script

Here, in order to make MySQL database backup and recovery meet our actual requirements, use a Shell script to automate the entire backup process.

[Root @ CentOS ~] # Vi mysql-backup.sh notebook create database automatic backup script, as follows:

 
 
  1. #!/bin/bash   
  2. PATH=/usr/local/sbin:/usr/bin:/bin   
  3. # The Directory of Backup   
  4. BACKDIR=/backup/mysql   
  5. # The Password of MySQL   
  6. ROOTPASS= 

Replace the star number with the MySQL root Password.

 
 
  1. # Remake the Directory of Backup   
  2. rm -rf $BACKDIR   
  3. mkdir -p $BACKDIR   
  4. # Get the Name of Database   
  5. DBLIST=`ls -p /var/lib/mysql | grep / | tr -d /`   
  6. # Backup with Database   
  7. for dbname in $DBLIST   
  8. do   
  9. mysqlhotcopy $dbname -u root -p $ROOTPASS $BACKDIR | logger -t mysqlhotcopy   
  10. done 

[2] Run the MySQL database automatic backup script

[Root @ CentOS ~] # Chmod 700 mysql-backup.sh changes the script properties so that it can only be executed by the root user

[Root @ CentOS ~] #./Mysql-backup.sh run script

[Root @ CentOS ~] # Ls-l/backup/mysql/check whether the backup is successful

Total 8

Drwxr-x --- 2 mysql 4096 Sep 1 mysql has been successfully backed up to the/backup/mysql directory

[3] Let the database backup script run automatically every day

[Root @ sample ~] # Crontab-e ← edit the automatic running rule and an editing window appears. The operation is the same as that in vi)

00 03 ***/root/mysql-backup.sh add this line to the file, let the database back up at every day

How to test whether automatic backup is normal or not)

Here, we will introduce the recovery method after the problem occurs through the actual operation process.

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.