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