Mysql is automatically backed up in centos, And the backup file is transferred to another machine for backup.

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.