Copy Code code as follows:
The requirement imports the Tb_a table from the Ser_a library on the 192.168.3.5 to the Ser_b library on the 192.168.3.6 at 5 points per day, and the table name is also called Tb_a
Server-side scripting/usr/shell_clubs/auto_sql/server.sh
#!/bin/sh
#code by Scpman
/usr/bin/find/usr/shell_clubs/auto_sql/-name "*.sql"-mtime +3|xargs rm #del Old SQL
#get New SQL
Time= ' Date +%y%m%d '
mysqldump-uroot-p123456 ser_a tb_a >/usr/shell_clubs/auto_sql/' Date +%y%m%d ' _tb_a.sql
Sleep 2
ssh-p10022 192.168.3.6 <<eee
/usr/shell_clubs/auto_sql/client.sh
EEE
Description: The server-side script will export the specified table and SSH to the target machine via the public key, calling client script
Client Script/usr/shell_clubs/auto_sql/client.sh
#!/bin/sh
#code by Scpman
#client. Sh
Time= ' Date +%y%m%d '
/usr/bin/find/usr/shell_clubs/auto_sql/-name "*.sql"-mtime +3|xargs rm #del Old SQL
/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/;
counts= ' Ls-l/usr/shell_clubs/auto_sql/| grep "$time" | awk ' {print $NF} ' |wc-l '
Echo $counts
If ["$counts"-eq 1]
Then
echo sql: $counts
Mysql-uroot-ptest123 <<FFF
Use Ser_b;
drop table tb_a;
FFF
Mysql-uroot-ptest123 Ser_b </usr/shell_clubs/auto_sql/' Date +%y%m%d ' _tb_a.sql--default-character-set=utf8
Echo--------------Done
Else
echo SQL wrong
Fi
Description: When a client script is invoked, it deletes the old SQL record under the current path and then synchronizes the tables exported by the server through rsync, and checks to see if synchronization is successful, emptying the existing old tb_a and importing the new tb_a into the library, if not synchronized successfully, Then the script exits (here you can send a mail notification before exiting)
And then the flow is through.
Now add a timer on the 192.168.3.5 (server side)
# #send SQL to 192.168.3.6
0 5 * * * su-root-c "/usr/shell_clubs/auto_sql/server.sh" >>/usr/shell_clubs/auto_sql/res.log