Linux Learning Diary-shell scripts and Scheduled Tasks

Source: Internet
Author: User
Tags mysql backup

This article will aim to implement regular automatic backups of the MySQL database, and introduce the perfect collaborative process between shell scripts and scheduled tasks. Where the shell script is responsible for the specific backup operation, the Crond server is responsible for controlling the backup cycle.

"Confirm Backup Scenario"

    1. Backup host: The IP address is 192.168.4.110, the target host is connected through the in-Cabinet network.

    2. Database server: The IP address for the 192.168.4.11,mysql service listening port is 3306.

    3. Backup content: Remote backup of STUDYDB,COURSDB library in MySQL server, daily 2:30, each library backs up a separate. sql file, and then compresses to. tar.gz format, embedded in the file name, the date and time that the backup was performed.

(i) create a dedicated database backup account operator, which allows connection to the MySQL database from the backup host 192.168.4.110 and grants read access to the Studydb,coursedb library.

Create User: Log in as root input:

mysql> CREATE USER ' Operator ' @ ' 192.168.4.110 ' idendified by ' pwd123 ';

Grant operator Permissions:

Mysql> GRANT All on * * to ' Operator ' @ '% '; For testing convenience here gives the maximum permissions

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/89/7A/wKiom1gUalSDmXhyAABW8iKHfWI108.png "title=" 1.png " alt= "Wkiom1gualsdmxhyaabw8ikhfwi108.png"/>

(ii) then test the database access from the backup host, check whether authorization is valid, or use the Mysqldump Backup tool directly for testing.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/89/7A/wKiom1gUcmzisDydAABL1klQBZI385.png "title=" 2.png " alt= "Wkiom1gucmzisdydaabl1klqbzi385.png"/>

"Writing mSQL Backup Scripts"

First create a backup directory:

[Email protected]~]# mkdir-p/opt/qnzx_dbbak

Then write the appropriate backup script:

[[Email protected]~]# vim/qnzx_dbbak.sh

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/89/84/wKiom1gV-_-BlKaNAADPoiXslIs870.png "style=" float: none; "title=" 3.png "alt=" Wkiom1gv-_-blkanaadpoixslis870.png "/>

Add permissions and execute, and then view the backup results:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/89/81/wKioL1gV-_-izFqDAABVhJYTdjk843.png "style=" float: none; "title=" 4.png "alt=" Wkiol1gv-_-izfqdaabvhjytdjk843.png "/>

"Set up Scheduled Tasks"

1. Transfer scripts to the backup directory

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/89/84/wKiom1gV_eWDvCg_AAAu44du6ZY890.png "style=" float: none; "title=" 5.png "alt=" Wkiom1gv_ewdvcg_aaau44du6zy890.png "/>

2. Create a scheduled task specify the time to execute the script

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/89/81/wKioL1gV_ebRcUOjAAAf_eQoMq4028.png "style=" float: none; "title=" 6.png "alt=" Wkiol1gv_ebrcuojaaaf_eqomq4028.png "/>

3. Ensure that the Crond service is running

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/89/84/wKiom1gV_pHizJs2AAAmFPf884A359.png "title=" 7.png " alt= "Wkiom1gv_phizjs2aaamfpf884a359.png"/>

The above is to create the contents of the MySQL backup script, if you feel good, give me a praise of it ~\ (≧▽≦)/~

If there is any shortage of great God, please let me know, I will correct it in time!

This article is from the "Dark Cloud Technology" blog, please be sure to keep this source http://wuyunkeji.blog.51cto.com/12028005/1867456

Linux Learning Diary-shell scripts and Scheduled Tasks

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.