/bin/bash
conffile=/usr/local/sbin/cvsback.conf
logfile=/usr/local/sbin/cvsback.log
tmppath=/tmp
srcok=1
today=`date +%Y%m%d`
for item in `cat $conffile |grep -v ^#|sed "/^$/d"`
do
# echo $item
date +%Y%m%d-%H:%M:%S >> $logfile
src=`echo $item|cut -d":" -f1`
desthost=`echo $item|cut -d":" -f2`
destpath=`echo $item|cut -d":" -f3`
#echo $src
#echo $desthost
#echo $destpath
if [ -d $src ]
then
echo "src ok,it is a directory"|/usr/bin/tee -a $logfile
srcok=0
elif [ -f $src ]
then
echo "src ok,it is a file"|/usr/bin/tee -a $logfile
srcok=0
else
echo "$src not exist"|/usr/bin/tee -a $logfile
continue
fi
echo -n "backup $src..."|/usr/bin/tee -a $logfile
bfname=$tmppath/`basename $src`-$today.tgz
#echo $bfname
tar czf $bfname $src >> $logfile 2>> $logfile
if [ $? -eq 0 ]
then
echo "done"|/usr/bin/tee -a $logfile
scp $bfname root@$desthost:$destpath/
if [ $? -eq 0 ]
then
rm -f $bfname
fi
fi
ssh 21.17.98.2 "[ $destpath/`basename $src`-`date -d'7days ago' +%Y%m%d`.tgz ]" > /dev/null 2> /dev/null
if [ $? -eq 0 ]
then
ssh 11.17.98.7 "rm -f $destpath/`basename $src`-`date -d'7days ago' +%Y%m%d`.tgz"
fi
done
conffile=/usr/local/sbin/cvsback.conf
logfile=/usr/local/sbin/cvsback.log
tmppath=/tmp
srcok=1
today=`date +%Y%m%d`
for item in `cat $conffile |grep -v ^#|sed "/^$/d"`
do
# echo $item
date +%Y%m%d-%H:%M:%S >> $logfile
src=`echo $item|cut -d":" -f1`
desthost=`echo $item|cut -d":" -f2`
destpath=`echo $item|cut -d":" -f3`
#echo $src
#echo $desthost
#echo $destpath
if [ -d $src ]
then
echo "src ok,it is a directory"|/usr/bin/tee -a $logfile
srcok=0
elif [ -f $src ]
then
echo "src ok,it is a file"|/usr/bin/tee -a $logfile
srcok=0
else
echo "$src not exist"|/usr/bin/tee -a $logfile
continue
fi
echo -n "backup $src..."|/usr/bin/tee -a $logfile
bfname=$tmppath/`basename $src`-$today.tgz
#echo $bfname
tar czf $bfname $src >> $logfile 2>> $logfile
if [ $? -eq 0 ]
then
echo "done"|/usr/bin/tee -a $logfile
scp $bfname root@$desthost:$destpath/
if [ $? -eq 0 ]
then
rm -f $bfname
fi
fi
ssh 21.17.98.2 "[ $destpath/`basename $src`-`date -d'7days ago' +%Y%m%d`.tgz ]" > /dev/null 2> /dev/null
if [ $? -eq 0 ]
then
ssh 11.17.98.7 "rm -f $destpath/`basename $src`-`date -d'7days ago' +%Y%m%d`.tgz"
fi
done
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/90618/viewspace-609497/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/90618/viewspace-609497/