自己编写自动同步脚本
2018-03-09 18:34
281 查看
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
*/
运行脚本,将结果保存到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
*/
相关文章推荐
- Linux编写Shell脚本自动同步svn并发布maven项目-SSH连接远程服务
- svn commit-email自动发送邮件乱码问题的解决,以及自己写svn同步邮件脚本
- [置顶] 让Linux系统启动过程自动运行自己编写的脚本
- Linux开机如何自动运行自己编写好的shell脚本
- 朋友的一个问题:Linux开机如何自动运行自己编写好的shell脚本
- 自己编写了Oracle EBS程序自动移植脚本
- Linux编写Shell脚本自动同步svn并发布maven项目-Linux服务器用户设置
- linux 自己编写脚本,开机自动启动
- python自动化运维-编写rsync+sersync安装脚本实现文件实时同步
- 用java robot编写自己的机器人,实现自动测试
- Python语言编写电脑时间自动同步小工具
- 通过VBS编写自动输入账号和密码、自动登录程序的脚本
- 自己动手编写devExpress组件自动安装程序
- D3D游戏编程系列(四):自己动手编写即时战略游戏之网络同步
- D3D游戏编程系列(四):自己动手编写即时战略游戏之网络同步
- 使用expect脚本自动下载和同步代码
- 自动同步服务器vm文件的shell脚本
- 人机猜拳游戏(自己编写shell脚本)
- 在ubuntu linux 中编写一个自己的python脚本
- Python编写的读取html文件名,自动编写SQL插入语句脚本