Step1:

运行脚本,将结果保存到sync_date.log下;

执行的时候,将地址修改为slave ip

--databases 指定为需要同步的db_name

user 和password修改为对应的账号密码;

自己编写自动同步脚本

自己编写自动同步脚本

/*

#!/bin/bash


#define sync function
sync(){
a=`pt-table-sync --execute --sync-to-master --lock 1 --print --charset=utf8 --verbose --databases itdb u=copy2,p=jsddwcc,h=10.8.135.156,P=3306`
echo -e "$a"
}


#output sync to log file
path=sync_`date +%Y%m%d.log`


sync > $path




#print sync result 


echo "Sync OK, plese check $path"

*/

Step 2:

运行 sh sync.sh  slave_address  db_name  slave_user_name  slave_password的方式:

一共四个参数,依次进行;

自己编写自动同步脚本自己编写自动同步脚本

/*

#!/bin/bash


#define sync function
#h is host ,this is slave address
#the charset is setted utf8, if your table is not utf8, remove it
#lock could be 0 - 3, 0=don't lock; 1 lock sync part; 2 lock table ;3 lock server;


slave_add=$1
slave_db=$2
slave_user=$3
slave_pass=$4


sync(){
a=`pt-table-sync --execute --sync-to-master --lock 1 --print --charset=utf8 --verbose --databases $slave_db u=$slave_user,p=$slave_pass,h=$slave_add,P=3306`
echo -e "$a"
}


#output sync to log file
path=sync_`date +%Y%m%d.log`


sync > $path




#print sync result 


echo "Sync OK, plese check $path"

*/

Step3:

当用户未输入4个参数的时候,给出提示;

自己编写自动同步脚本

自己编写自动同步脚本

/*

#!/bin/bash


#define sync function
#h is host ,this is slave address
#the charset is setted utf8, if your table is not utf8, remove it
#lock could be 0 - 3, 0=don't lock; 1 lock sync part; 2 lock table ;3 lock server;


slave_add=$1
slave_db=$2
slave_user=$3
slave_pass=$4


sync(){
a=`pt-table-sync --execute --sync-to-master --lock 1 --print --charset=utf8 --verbose --databases $slave_db u=$slave_user,p=$slave_pass,h=$slave_add,P=3306`
echo -e "$a"
}




if [ $# -ne 4  ]
then
echo 
echo Usage: sh script.sh Slave_Address db_name Slave_username Slave_password;
echo There has 4 parameters. No error in the order of the parameters;
echo Plese try again
echo
else
#output sync to log file
path=sync_`date +%Y%m%d.log`
sync > $path


#print sync result 
echo "Sync OK, plese check $path"
fi

 */

相关文章:

  • 2022-02-18
  • 2022-12-23
  • 2021-11-04
  • 2021-11-08
  • 2021-11-04
  • 2022-12-23
  • 2021-09-07
猜你喜欢
  • 2021-08-10
  • 2022-12-23
  • 2021-08-04
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-03-02
相关资源
相似解决方案