You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/12.4.md
+30-27Lines changed: 30 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -68,43 +68,44 @@ In order to periodically synchronize files, you can set up a crontab file that w
68
68
69
69
## MySQL backup
70
70
71
-
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.
71
+
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.
72
72
73
-
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.
73
+
A shell script is generally used to implement regular cold backups of databases, executing synchronization tasks using rsync in a non-local mode.
74
74
75
-
The following is a scheduled backup MySQL backup script, we use the mysqldump program, this command can be exported to a database file.
75
+
76
+
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.
76
77
77
78
78
79
#!/bin/bash
79
-
# The following configuration information, modify their own
80
+
# Configuration information; modify it as needed
80
81
mysql_user="USER" #MySQL backup user
81
82
mysql_password="PASSWORD" # MySQL backup user's password
82
83
mysql_host="localhost"
83
84
mysql_port="3306"
84
-
mysql_charset="utf8" # MySQL coding
85
-
backup_db_arr=("db1" "db2") # To back up the database name, separated by spaces separated by a plurality of such("db1" "db2" "db3")
86
-
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
87
-
expire_backup_delete="ON" # delete outdated backups is turned OFF to ON ON to OFF
88
-
expire_days=3 # default expiration time for the three days the number of days, this is only valid when the expire_backup_delete open
89
-
90
-
# We do not need to modify the following start
91
-
backup_time=`date +%Y%m%d%H%M` # define detailed time backup
92
-
backup_Ymd=`date +%Y-%m-%d` # define the backup directory date time
85
+
mysql_charset="utf8" # MySQL encoding
86
+
backup_db_arr=("db1" "db2") # Name of the database to be backed up, separating multiple databases wih spaces ("DB1", "DB2" db3")
87
+
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
88
+
expire_backup_delete="ON" # Whether to delete outdated backups or not
89
+
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"
90
+
91
+
# We do not need to modify the following initial settings below
92
+
backup_time=`date +%Y%m%d%H%M` # Define the backup time format
93
+
backup_Ymd=`date +%Y-%m-%d` # Define the backup directory date time
93
94
backup_3ago=`date-d '3 days ago '+%Y-%m-%d` # 3 days before the date
94
-
backup_dir=$backup_location/$backup_Ymd # full path to the backup folder
95
-
welcome_msg="Welcome to use MySQL backup tools!" # greeting
95
+
backup_dir=$backup_location/$backup_Ymd # Full path to the backup folder
96
+
welcome_msg="Welcome to use MySQL backup tools!" # Greeting
96
97
97
-
# Determine whether to start MYSQL, mysql does not start the backup exit
98
+
# Determine whether to MySQL is running; if not, then abort the backup
echo "All databases have been successfully backed up! Thank you!"
148
149
exit
149
150
fi
150
151
151
152
152
-
Modify shell script attributes:
153
+
Modify the properties of the shell script like so:
153
154
154
155
chmod 600 /root/mysql_backup.sh
155
156
chmod +x /root/mysql_backup.sh
156
157
157
-
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.
158
+
Then add the crontab command:
158
159
159
160
00 00 *** /root/mysql_backup.sh
160
161
162
+
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.
163
+
161
164
## MySQL Recovery
162
165
163
166
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.
0 commit comments