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

Source: Internet
Author: User
1. First, create a backup directory and backup script file. this is not much to mention. 2. back up and submit the file as follows :#! /Bin/bashnow =$ (date + & quot; % Y % m % d & quot ;) # obtain the current date days = 5bk_dr =/# path to the backup directory find $ bk_dr/backup file name-mtime + $ days-execrm-rf {}\; # Delete $ days

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.