Mysql is automatically backed up in centos, And the backup file is transferred to another machine for backup.
1. Create a backup directory and a backup script file.
2. Submit the backup file as follows:
#! /Bin/bash
Now = $ (date + "% Y % m % d") # Get the current date
Days = 5
Bk_dr = // # path of the Backup Directory
Find $ bk_dr/backup file name-mtime + $ days-exec rm-rf {}\; # Delete the backup file of $ days
Mysqldump-u database account-p Database Password Database to be backed up | gzip> $ bk_dr/exported file name $now. SQL .gz
Username = root
Chown-R $ username: $ username $ bk_dr # Set the backup file owner
Scp $ bk_dr/exported file name $ now. SQL linux Account @ Server IP address to be backed up:/path
(Scp is used here. In order not to enter the password of the backup server every time, you need to set machine trust or use ftp or other methods)
3. Set ssh Trust for two machines
Use the ssh-keygen-t rsa command to create a trust certificate
Ssh B @ B mkdir-p. ssh create a. ssh directory on the machine to be backed up to store certificates
Cat. ssh/id_rsa.pub | ssh B @ B 'cat>. ssh/authorized_keys copy the certificate to the Created directory and change it to authorized_keys.
In this way, you can use the ssh command to test the ssh user @ IP
4. Convert the backup file into an executable file
Chmod + x file path
5. Create a task plan
Vi/etc/crontab
Add a line of Command: the location of the Command execution file required by the account for execution time *** user Command/(you can query crond for details) Restart crontab/etc/rc. d/init. d/crond restart start run: chkconfig crond on restart service crond restart