In general, the environment:
The MySQL database address is 10.254.254.23, you want to back up the database to the other folder in this machine, and the backup data will be transferred to another 10.254.254.29 machine by means of incremental backup.
Implementation method:
Back up the native MySQL: (Refer to: http://my.oschina.net/u/919074/blog/223920)
First step: Configure the backup directory code on the server:
--------------------------------------------------------------------------------
Mkdir/var/lib/mysqlbackup
Cd/var/lib/mysqlbackup
--------------------------------------------------------------------------------
Step Two: Write the backup script code:
--------------------------------------------------------------------------------
VI dbbackup.sh
--------------------------------------------------------------------------------
Paste the following code, and make sure to change the Username,password and dbname.
Code:
--------------------------------------------------------------------------------
#!/bin/sh
Mysqldump-uuser -Ppassword dbname | gzip >/var/lib/mysqlbackup/dbname ' Date +%y-%m-%d_%h%m%s '. sql.gz
Cd/var/lib/mysqlbackup
Rm-rf ' Find. -name ' *.sql.gz '-mtime 5 ' #删除5天前的备份文件
--------------------------------------------------------------------------------
Step Three: change backup script permissions
Code:
--------------------------------------------------------------------------------
chmod +x dbbackup.sh
--------------------------------------------------------------------------------
Fourth step: Execute the Backup script code with CRONTAB timing:
--------------------------------------------------------------------------------
Vi/etc/crontab
Write:
4 * * */var/lib/mysqlbackup/dbbackup.sh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The above steps are implemented, to back up the file to the local, then the more secure way is to copy this file on the remote machine also copied a copy
So on the 10.254.254.29 Linux machine: (Refer to: http://servershuji.blog.51cto.com/1283121/580628/)
First copy the file you want to use on the 10.254.254.29 machine, because it will be a bit slow with rsync, but no file update will automatically recognize and copy the tool.
Scp-r [email protected]:/home/db_backup//home/zabbix_backup
Then 10.254.254.29 to consider not each copy with a password, so we have to use the SSH method to generate a secret key, let 10.254.254.29 fully accept 10.254.254.23, do not enter the password;
The method is:
On the 29 machine:
Ssh-keygen–d or ssh-keygen–t RSA
Upload to the root of 23 under SSH:
Ssh-copy-id-i ~/.ssh/id_dsa.pub [email protected]
This implements the method of executing the rsync command on 29 without entering the password:
Then use the following command to test if a password is required:
Rsync-avzh [email protected]:/home/db_backup/ /home/zabbix_backup
Then, by planning the task, let this command be synchronized every half-hour:
Vi/etc/crontab
0 */2 * * * root rsync-avzh [email protected]:/home/db_backup/ /home/zabbix_backup
Please correct me if you have any questions.
This article is from the "Sulan Network" blog, so be sure to keep this source http://zhangfang526.blog.51cto.com/8588740/1708342
Backup Myssql and using rsync for backups and transfers