Mysql backup mainly includes hot backup and cold backup. Here, hot backup is used, that is, the SQL statement exported by mysqldump is used for backup. In this case, backup is performed every morning.
Mysql backup mainly includes hot backup and cold backup. Here, hot backup is used, that is, the SQL statement exported by mysqldump is used for backup. In this case, backup is performed every morning.
1. Configure the Database Server
1. Write the mysql automatic backup script
Mysql backup mainly includes hot standby and Cold Standby. Hot Standby is used here, that is, the SQL statement exported by mysqldump is used for backup.
# Vi/etc/mysqlback. sh
#! /Bin/bash
DB_NAME = "luwenju" // database to be backed up
DB_USER = "luwenju" // database username
DB_PASS = "luwenju" // Database Password
BIN_DIR = "/usr/local/mysql/bin" // mysql environment variable
BACK_DIR = "/opt" // backup file to save data
DATE = "'date + % Y % m % d '"
$ BIN_DIR/mysqldump-opt-u $ DB_USER-p $ DB_PASS $ DB_NAME> $ BACK_DIR/luwenju _ $ DATE. SQL
# Chmod + x/etc/mysqlback. sh
Test
#/Etc/mysqlback. sh
# Ls/opt/
Luwenju_20151126. SQL
2. Set a regular backup cycle
In this case, backup is performed every morning. The specific backup cycle is based on the specific application.
# Crontab-e
0 0 ***/etc/mysqlback. sh
#/Etc/init. d/crond restart
3. Install rsync
# Tar zxvf rsync-3.0.8.tar.gz
# Cd rsync-3.0.8
#./Configure & make install
Create a configuration file and add the following content:
# Vi/etc/rsync. conf
Uid = nobody
Gid = nobody
Use chroot = no
Max connections = 10
Pid file =/var/run/rsyncd. pid
Lock file =/var/run/rsyncd. lock
Log file =/var/log/rsyncd. log
Port = 873
Timeout = 300
[Backup]
Read only = yes // read-only mode
List = yes
Ignore errors
Comment = This is a file back
Path =/opt // directory to be synchronized
Auth users = test // verify the user
Secrets file =/etc/rsync. passwd // verify the password path
Hosts allow = 119.232.33.246 // client that can be connected