Docs/shell/rsync同步/rsync_client_dr.sh.md
2022-10-18 16:59:37 +08:00

68 lines
No EOL
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

```
#!/bin/bash
##Edit by wangsuipeng
##Date 2016/10/25
## Rsync 客户端脚本-用于灾备环境搭建
##
## 脚本说明:
##
## 操作说明:执行过本脚本以后,需要添加到定时任务中
## 并删除定时任务中的其他应用同步命令,即
## 带有/opt/appl/assist/rsync/的脚本,为
## 安全起见,请确认是否是应用同步脚本
##项目名
read -p "The Project name[Not username]" PRO_NAME
##服务端IP
read -p "The Server IP:" PRO_HOST_IP
##容器
read -p "The Software[jboss/tomcat]:" SOFT
yum -y install rsync xinetd > /dev/null 2>&1
##脚本存放位置
DIRPATH=/usr/local/rsync
##密码文件
PASS_CFG=$DIRPATH/rsyncd.pass
##脚本文件
SCRIPT=$DIRPATH/rsync_${PRO_HOST_IP}-${PRO_NAME}.sh
EXCLUDE_CONF()
{
cat > /usr/local/rsync/exclude << EOF
log/*
logs/*
temp/*
backup/*
deployment/*
*.tar.gz
*.tgz
*.log
*.out
jdk*
work/*
EOF
}
if [ -d $DIRPATH ]
then
if [ -f $DIRPATH/rsyncd.pwd ]
then
cd $DIRPATH && tar zcvf bak.`date +%d%H%M`.tar.gz --exclude *.tar.gz * --remove-files >/dev/null 2>&1
fi
else
mkdir -p $DIRPATH
fi
EXCLUDE_CONF
echo "#!/bin/bash" > $SCRIPT
echo "/usr/bin/rsync -arP --delete --bwlimit=200 --exclude-from=/usr/local/rsync/exclude --password-file=$PASS_CFG rsync@$PRO_HOST_IP::${PRO_NAME}19 /opt/appl/$PRO_NAME/$SOFT" >> $SCRIPT
chmod +x $SCRIPT
echo "123456" > $PASS_CFG
```