#!/bin/bash
echo -e "升级client_x输入 [1]"
echo -e "升级new_client_xmobile输入[2]"
echo -e "升级client_xmobile输入 [3]"
echo -e "升级server_x输入 [4]"
echo -e "升级server_new输入 [5]"
echo -e "升级pay输入 [6]"
read -p "输入推送目标目录:" -t 30 pram
if [ -z $pram ];then
echo "ERR:参数不能为空!"
exit 2
fi
if [ $pram -gt 6 -o $pram -lt 0 ];then
echo "ERR:输入选项有误!"
exit 2
fi
case $pram in
1)
dir="client_x"
;;
2)
dir="new_client_xmobile"
;;
3)
dir="client_xmobile"
;;
4)
dir="server_x"
;;
5)
dir="server_new"
;;
6)
dir="pay"
;;
esac
source="/www/gray/pro_xm/$dir"
if [ ! -d "$source" ];then
echo ERR:源目录"$source"不存在!
exit 2
fi
datename=$(date +%Y%m%d-%H%M%S)
destination=/www/xmcp
excludedir=/root/shell/exclude.list
backupsrc=${destination}/${dir}
backupdes=/home/syn_bak/${dir}-${datename}
if [ $pram -eq 6 ];then
payexclude="--exclude=images/"
synlist=`cat /root/shell/pay.list`
elif [ $pram -eq 4 ];then
payexclude=
synlist=`cat /root/shell/server.list`
cp -ra $backupsrc $backupdes
rsync -ravzpotg --progress --exclude-from="$excludedir" $payexclude --delete $source $destination
else
payexclude=
synlist=`cat /root/shell/syn.list`
cp -ra $backupsrc $backupdes
rsync -ravzpotg --progress --exclude-from="$excludedir" $payexclude --delete $source $destination
fi
if [ $? -gt 0 ];then
echo "ERR:本机推送出错,退出!"
exit 2
fi
echo -------------------本机同步完成----------------------
for i in $synlist
do
if [ -z $i ];then
echo 列表为空,退出!
exit 0
fi
ip=`echo $i | cut -d ":" -f 1`
port=`echo $i | cut -d ":" -f 2`
user=`echo $i | cut -d ":" -f 3`
passwd=`echo $i | cut -d ":" -f 4`
synpass=`echo $i | cut -d ":" -f 5`
/usr/expect/bin/expect <<-EOF
set time 30
spawn ssh root@$ip
expect {
"*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$passwd\r" }
}
expect "*#"
send "cp -ra $backupsrc $backupdes\r"
expect "*#"
send "exit\r"
expect eof
set time 30
spawn rsync -ravzpotg --port=$port --progress --exclude-from=$excludedir $payexclude --delete $source $user@$ip::syn
expect "*Password:" { send "$synpass\r" }
expect eof
EOF
#echo -------------------$ip备份完成------------------------
if [ $? -gt 0 ];then
echo "ERR:远程$ip推送出错,退出!"
exit 2
fi
echo -------------------$ip同步完成------------------------
done
项目同步脚本
最新推荐文章于 2024-04-17 16:50:34 发布
该脚本是一个bashshell脚本,用于选择并升级不同的服务目录,如client_x、new_client_xmobile等。它使用rsync进行本地备份和同步,并通过ssh进行远程服务器的同步。脚本还包含了排除特定目录的功能以及处理错误的情况。
摘要由CSDN通过智能技术生成