shell 脚本一例 curl rsync

#!/bin/bash

#netstat -anp | grep rsync | wc -l
#ps -fe|grep rsync |grep -v grep

logfile="/var/log/rsyncindex-`date +%Y-%m-%d`.out"
touch $logfile

vcur=`date +%s`
vuser="228"
vip=$(ifconfig | awk -F'addr:|Bcast' '/Bcast/{print $2}')
vurl='http://127.0.0.1:8080/ssss'
vurlislock="$vurl/index/islock"
vurllock="$vurl/index/lock/$vuser"
vurlrelease="$vurl/index/release/$vuser"
vrsync=`ps -fe|grep rsync |grep -v grep`

echo "`date +%T-%D` index.rsync starting..." >> $logfile



rlock=`curl $vurllock`
echo "`date +%T-%D` index.rsync lock $vurllock $rlock" >> $logfile
rlockflag=${rlock:1:1}
echo "`date +%T-%D` index.rsync lock success! $rlock $rlockflag" >> $logfile


#rsync -vzrtopg --progress --delete --password-file=/etc/rsync.pas rsyncuser@127.0.0.1::SEARCH /mnt/search/SEARCH_INDEX


	if [ $rlockflag == 1 ]
	then
		RDIR='SEARCH/'
		TDIR='/mnt/search/SEARCH_INDEX'
		RADD='127.0.0.1'
		BAKUSER='rsyncuser'
		PROG='/usr/bin/rsync'
		OPTIONS='-vzrtopg --progress --delete --password-file=/etc/rsync.pas'
		LDIR='/mnt/search/SEARCH_INDEX_RSYNC'
		BDIR='/mnt/search/SEARCH_INDEX_BACKUP'
		#export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
		#export RSYNC_PASSWORD='lk_lskdjf(*&(^*%KJhj'


		touch $LDIR
		rm -rf $LDIR
		
		echo "`date +%T-%D` index.rsync remove $LDIR" >> $logfile

		$PROG $OPTIONS $BAKUSER@$RADD::$RDIR $LDIR
		
		if [ $?==0 ]
			then
			echo "`date +%T-%D` index.rsync sync success! $?" >> $logfile
			rrelease=`curl $vurlrelease`
			echo "`date +%T-%D` index.rsync release $vurlrelease $rrelease" >> $logfile
			if [ $rrelease==1 ]
				then
				echo "`date +%T-%D` index.rsync release the index file success! $rrelease" >> $logfile
				
				
				mv $TDIR $BDIR
				echo "`date +%T-%D` index.rsync move $TDIR to $BDIR" >> $logfile
				
				mv $LDIR $TDIR
				echo "`date +%T-%D` index.rsync move $LDIR to $TDIR" >> $logfile
				
				
				rm -rf $BDIR
				echo "`date +%T-%D` index.rsync remove $BDIR" >> $logfile
				
			else
				echo "`date +%T-%D` index.rsync release the index file exception! $rrelease" >> $logfile
			fi
		else
			echo "`date +%T-%D` index.rsync sync exception! $?" >> $logfile
		fi
	else
		echo "`date +%T-%D` rsync could not run,because failed to lock the index file " >> $logfile
	fi

echo "`date +%T-%D` index.rsync complete! $rlock" >> $logfile

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值