Fix translation for section "MySQL backup" in 12.4.md

This commit is contained in:
Anchor
2015-01-03 16:39:55 -08:00
committed by James Miranda
parent e1d513b7bc
commit d2d94581f2

View File

@@ -68,43 +68,44 @@ In order to periodically synchronize files, you can set up a crontab file that w
## MySQL backup
MySQL database application is still the mainstream, the current MySQL backup in two ways: hot backup and cold backup, hot backup is currently mainly used master/slave mode (master/slave) mode is mainly used for database synchronization separate read and write, but also can be used for hot backup data ), on how to configure this information, we can find a lot. Cold backup data, then that is a certain delay, but you can guarantee that the time period before data integrity, such as may sometimes be caused by misuse of our loss of data, then the master/slave model is able to retrieve lost data, but through cold backup can partially restore the data.
MySQL databases are still the mainstream, go-to solution for most web applications. The two most common methods of backing up MySQL databases are hot backups and cold backups. Hot backups are usually used with systems set up in a master/slave configuration to backup live data (the master/slave synchronization mode is typically used for separating database read/write operations, but can also be used for backing up live data). There is a lot of information available online detailing the various ways one can implement this type of scheme. For cold backups, incoming data is not backed up in real-time as is the case with hot backups. Instead, data backups are performed periodically. This way, if the system fails, the integrity of data before a certain period of time can still be guaranteed. For instance, in cases where a system malfunction causes data to be lost and the master/slave model is unable to retrieve it, cold backups can be used for a partial restoration.
Cold backup shell script is generally used to achieve regular backup of the database, and then rsync synchronization through the above described non-local one server room.
A shell script is generally used to implement regular cold backups of databases, executing synchronization tasks using rsync in a non-local mode.
The following is a scheduled backup MySQL backup script, we use the mysqldump program, this command can be exported to a database file.
The following is an example of a backup script that performs scheduled backups for a MySQL database. We use the `mysqldump` program which allows us to export the database to a file.
#!/bin/bash
# The following configuration information, modify their own
# Configuration information; modify it as needed
mysql_user="USER" #MySQL backup user
mysql_password="PASSWORD" # MySQL backup user's password
mysql_host="localhost"
mysql_port="3306"
mysql_charset="utf8" # MySQL coding
backup_db_arr=("db1" "db2") # To back up the database name, separated by spaces separated by a plurality of such("db1" "db2" "db3")
backup_location=/var/www/mysql # backup data storage location, please do not end with a "/", this can keep the default, the program will automatically create a folder
expire_backup_delete="ON" # delete outdated backups is turned OFF to ON ON to OFF
expire_days=3 # default expiration time for the three days the number of days, this is only valid when the expire_backup_delete open
mysql_charset="utf8" # MySQL encoding
backup_db_arr=("db1" "db2") # Name of the database to be backed up, separating multiple databases wih spaces ("DB1", "DB2" db3 ")
backup_location=/var/www/mysql # Backup data storage location; please do not end with a "/" and leave it at its default, for the program to automatically create a folder
expire_backup_delete="ON" # Whether to delete outdated backups or not
expire_days=3 # Set the expiration time of backups, in days (defaults to three days); this is only valid when the `expire_backup_delete` option is "ON"
# We do not need to modify the following start
backup_time=`date +%Y%m%d%H%M` # define detailed time backup
backup_Ymd=`date +%Y-%m-%d` # define the backup directory date time
# We do not need to modify the following initial settings below
backup_time=`date +%Y%m%d%H%M` # Define the backup time format
backup_Ymd=`date +%Y-%m-%d` # Define the backup directory date time
backup_3ago=`date-d '3 days ago '+%Y-%m-%d` # 3 days before the date
backup_dir=$backup_location/$backup_Ymd # full path to the backup folder
welcome_msg="Welcome to use MySQL backup tools!" # greeting
backup_dir=$backup_location/$backup_Ymd # Full path to the backup folder
welcome_msg="Welcome to use MySQL backup tools!" # Greeting
# Determine whether to start MYSQL, mysql does not start the backup exit
# Determine whether to MySQL is running; if not, then abort the backup
mysql_ps=`ps-ef | grep mysql | wc-l`
mysql_listen=`netstat-an | grep LISTEN | grep $mysql_port | wc-l`
if [[$mysql_ps==0]-o [$mysql_listen==0]]; then
echo "ERROR: MySQL is not running! backup stop!"
echo "ERROR: MySQL is not running! backup aborted!"
exit
else
echo $welcome_msg
fi
# Connect to mysql database, can not connect to the backup exit
# Connect to the mysql database; if a connection cannot be made, abort the backup
mysql-h $mysql_host-P $mysql_port-u $mysql_user-p $mysql_password << end
use mysql;
select host, user from user where user='root' and host='localhost';
@@ -113,11 +114,11 @@ The following is a scheduled backup MySQL backup script, we use the mysqldump pr
flag=`echo $?`
if [$flag!="0"]; then
echo "ERROR: Can't connect mysql server! backup stop!"
echo "ERROR: Can't connect mysql server! backup aborted!"
exit
else
echo "MySQL connect ok! Please wait......"
# Judgment does not define the backup database, if you define a backup is started, otherwise exit the backup
# Determine whether a backup database is defined or not. If so, begin the backup; if not, then abort
if ["$backup_db_arr"!=""]; then
# dbnames=$(cut-d ','-f1-5 $backup_database)
# echo "arr is(${backup_db_arr [@]})"
@@ -128,36 +129,38 @@ The following is a scheduled backup MySQL backup script, we use the mysqldump pr
`mysqldump -h $mysql_host -P $mysql_port -u $mysql_user -p $mysql_password $dbname - default-character-set=$mysql_charset | gzip> $backup_dir/$dbname -$backup_time.sql.gz`
flag=`echo $?`
if [$flag=="0"]; then
echo "database $dbname success backup to $backup_dir/$dbname-$backup_time.sql.gz"
echo "database $dbname successfully backed up to $backup_dir/$dbname-$backup_time.sql.gz"
else
echo "database $dbname backup fail!"
echo "database $dbname backup has failed!"
fi
done
else
echo "ERROR: No database to backup! backup stop"
echo "ERROR: No database to backup! backup aborted!"
exit
fi
# If you open the delete expired backup, delete operation
# If deleting expired backups is enabled, delete all expired backups
if ["$expire_backup_delete"=="ON" -a "$backup_location"!=""]; then
# `find $backup_location/-type d -o -type f -ctime + $expire_days-exec rm -rf {} \;`
`find $backup_location/ -type d -mtime + $expire_days | xargs rm -rf`
echo "Expired backup data delete complete!"
fi
echo "All database backup success! Thank you!"
echo "All databases have been successfully backed up! Thank you!"
exit
fi
Modify shell script attributes:
Modify the properties of the shell script like so:
chmod 600 /root/mysql_backup.sh
chmod +x /root/mysql_backup.sh
Set attributes, add the command crontab, we set up regular automatic backups every day 00:00, then the backup script directory/var/www/mysql directory is set to rsync synchronization.
Then add the crontab command:
00 00 *** /root/mysql_backup.sh
This sets up regular backups of your databases to the `/var/www/mysql` directory every day at 00:00, which can then be synchronized using rsync.
## MySQL Recovery
Earlier MySQL backup into hot backup and cold backup, hot backup main purpose is to be able to recover in real time, such as an application server hard disk failure occurred, then we can modify the database configuration file read and write into slave so that you can minimize the time interrupt service.