项目同步脚本

该脚本是一个bashshell脚本,用于选择并升级不同的服务目录,如client_x、new_client_xmobile等。它使用rsync进行本地备份和同步,并通过ssh进行远程服务器的同步。脚本还包含了排除特定目录的功能以及处理错误的情况。
摘要由CSDN通过智能技术生成
#!/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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值