The data on the server is so important that we have to back it up regularly! Here is a backup of MySQL and the use of rsync to synchronize files on the server, thus enabling the backup of files between multiple Linux servers.
A MySQL Backup
MySQL backup is relatively simple, with mysqldump to export the database that needs to be backed up, here is a shell script for everyone to reference, you can modify it to use your own database backup
#!/bin/sh########################################## #### crond scheduled backup MySQL database # @date 2015/09/25 Friday # @author yearnfar############################################ #DB_NAMES = ("DB1" "DB2" "DB3" "DB4" " DB5 ") bin_dir="/usr/local/mysql/bin " # mysql Execute file directory bck_dir="/data/mysql/backup/" # backup File Save directory date_month= ' date +%y%m ' month_day= ' date +%m%d ' date_format= ' date +%y%m%d ' # execute backup command for db_name in ${db_names[@]}; do mkdir -p $BCK _dir/$DATE _month/$MONTH _day $BIN _dir/ mysqldump --opt $DB _name | gzip > $BCK _dir/$DATE _month/$MONTH _day/$DB _name\_$ date_format.sql.gz # uses gzip compression to reduce the amount of hard disk use, because the timer runs every day if the backup, it takes up the hard disk sleep 1done
you will find that there is no account and password when mysqldump, because it is in my. CNF inside has been configured
[mysqldump]user=mysqldumppassword=123456
if not my. CNF in the configuration of the words will add a username and password
$BIN _dir/mysqldump--opt-umysqldump-p123456 $DB _name | gzip > $BCK _dir/$DATE _month/$MONTH _day/$DB _name\_$date_format.sql.gz
However, this will have the following hint, so it is recommended to add the my.cnf inside the data account and password!
Warning:using a password on the command line interface can is insecure.
PS:
1. The account recommendation for the Data Guide only grants Select and lock tables permissions, the command is as follows:
Grant Select,lock TABLES on db1.* to [e-mail protected] identified by ' 123456 '; ... ... ...
Two + servers for file backup
is it okay to back up the database and be safe? Certainly not, what if the disk on the server is damaged? Then the data will still be lost! And we want to make a backup may not only database files, some server generated files or users upload important files to be backed up, this time not only to back up on a machine, but to be on multiple machines on line backup!
here I introduce a method that uses Rsync for file synchronization, before writing an article about how to build the Rsync server: rsync Server Setup
The following configuration files are available here:
1. Server-side configuration:
Configuration file rsync.conf
# distributed under the terms of the gnu general public license v2# minimal configuration file for rsync daemon# see Rsync (1) and rsyncd.conf (5) man pages for help# this line is required by the /etc/init.d/rsyncd script# pid file = /var/run/ rsyncd.pidport = 873address = xxx.xxx.xxx.xxx # change to his own ipuid = Wwwgid = wwwuse chroot = yesread only = yes#limit access to private lanshosts allow=*hosts deny=*max connections = 5motd file = /etc/rsync.d/rsyncd.motd#This will give you a separate log file#log file = /var/log/rsync.log#this will log every file transferred - up to 85,000+ per user, per sync#transfer logging = yeslog format = %t %a %m %f %bsyslog facility = local3timeout = 300# Synchronizing database files [ mysql_backup]path = /data/mysql/backuplist = noignore errorsauth users = yearnfarsecrets file = /etc/rsync.d/rsyncd.secretscomment = mysql backup!!! # Sync Code [www_51open]path = /data/www/51open/uploadlist = noignore errorsauth users = yearnfarsecrets file = /etc/rsync.d/rsyncd.secretscomment = www/ 51open backup!!!
Configuration file Rsync.secrets
yearnfar:123456
2. Client Configuration:
Shell Script rsync.sh
#!/bin/sh# database file synchronization rsync-avzp--delete--password-file=/home/yearnfar/etc/rsyncd.secrets [email protected]::mysql_ backup/home/yearnfar/data/rsync/mysql_backup# Other files sync rsync-avzp--delete--password-file=/home/yearnfar/etc/ rsyncd.secrets [Email Protected]::www_51open/home/yearnfar/data/www/51open
Password configuration file rsyncd.secrets
123456
Execution of rsync.sh can be implemented to the server file synchronization to the client!!
3. So you can do it?
Is that OK? No!
Like the/home/yearnfar/data/www/51open directory just realizes the synchronization of files, and does not implement backup! If you want to back up, write a script to package the directory on a daily basis!
Is that OK? No!
...
Linux Server Data Backup