Shell preliminary: mysql regularly dumps local data every day to replace remote database data

Source: Internet
Author: User

Shell preliminary: mysql regularly resends local data every day and replaces remote database data 01mysql regularly resends local data every day, to replace the remote database data 02, You need to import the tb_a table in the ser_a database on 192.168.3.5 to the ser_ B database on 192.168.3.6 at every day, the table name is also tb_a03 server script/usr/shell_clubs/auto_ SQL/server. sh04 #! /Bin/sh05 # code by scpman06/usr/bin/find/usr/shell_clubs/auto_ SQL/-name "*. SQL "-mtime + 3 | xargs rm # del old sql07 # get new sql08time = 'date + % Y % m % d' 09mysqldump-uroot-p123456 ser_a tb_a>/usr/shell_clubs /auto_ SQL/'date + % Y % m % d' _ tb_a.sql10sleep 211ssh-p10022 192.168.3.6 <EEE12/usr/shell_clubs/auto_ SQL/client. sh13EEE14 Description: The server script exports the specified table and ssh the table to the target machine through the public key, and calls the client script 15 client script/usr/shell_clubs/auto_ SQL/client. sh1 6 #! /Bin/sh17 # code by scpman18 # client. sh19time = 'date + % Y % m % d' 20/usr/bin/find/usr/shell_clubs/auto_ SQL/-name "*. SQL "-mtime + 3 | xargs rm # del old sql21/usr/local/bin/rsync-vzrtopgl -- progress root@192.168.3.5 :: all/usr/shell_clubs/auto_ SQL/'date + % Y % m % d' _ tb_a. SQL/usr/shell_clubs/auto_ SQL /; 22 counts = 'LS-l/usr/shell_clubs/auto_ SQL/| grep "$ time" | awk '{print $ NF}' | wc-l' 23echo $ counts24if ["$ counts "-eq 1] 25then26echo SQL: $ counts27mysql-uroot-ptest123 <FFF28use ser_ B; 29 drop table tb_a; 30FFF31mysql-uroot-ptest123 ser_ B </usr/shell_clubs/auto_ SQL/'date + % Y % m % d' _ tb_a. SQL -- default-character-set = utf832echo ------------ explain echo SQL statement: when the client script is called, the old SQL record in the current path is deleted first, and then the table exported from the server is synchronized through rsync, and check whether the synchronization is successful, the existing tb_a is cleared and the new tb_a is imported into the database. If the synchronization fails, the script exits (an email notification can be sent to exit) 37 and then the streaming passed 38. Now add another timer on 192.168.3.5 (server side) 39 # send SQL to 192.168.3.6400 5 *** su-root-c "/usr/shell_clubs/auto_ SQL/server. sh ">/usr/shell_clubs/auto_ SQL/res. log

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.