#!/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
shell 脚本一例 curl rsync
最新推荐文章于 2023-11-17 14:15:47 发布