1. 程式人生 > >通過rsync備份靜態文件

通過rsync備份靜態文件

shell

腳本內容:

#!/bin/bash

dn=`dirname $0`

cd $dn

awk ‘/^[^#]/‘ rsync_dir.txt | while read line

do

i=1

dirarr=($line)

len=${#dirarr[@]}

if [ $len -gt 1 ] ; then

ipa=${dirarr[0]}

if ping -c 2 $ipa >/dev/null ;then

echo "$ipa is alive"

else

echo "$ipa is not alive"

continue

fi

else

echo "input \‘$line\‘ is error"

continue

fi


while [ $i -lt $len ]

do

res=${dirarr[$i]}

if ssh $ipa "[[ -d $res ]]" </dev/null ; then

dir=/backup_static_files/`date ‘+%Y%m%d‘`/${ipa}${res}

[[ ! -d $dir ]] && mkdir -pv $dir

rsync -auvrtzopgP --progress -e ssh $ipa:$res/ $dir

elif ssh $ipa "[[ -f $res ]]" </dev/null ; then

dir=/backup_static_files/`date ‘+%Y%m%d‘`/${ipa}`dirname $res`

[[ ! -d $dir ]] && mkdir -pv $dir

rsync -auvrtzopgP --progress -e ssh $ipa:$res $dir

else

echo "$res is not exist"

fi

i=$(($i+1))

done

done



文件rsync_dir.txt內容:

# ServerIp StaticFilesDir ...

10.10.45.82 /root/.ssh /usr/local/tomcatcluster /usr/local/nginx

10.10.1.142 /root/cut-apache /etc/httpd/conf /etc/httpd/conf.d /opt/IBM/WebSphere/Plugins/config/plugsrv /root/qiehuan1143.sh


通過rsync備份靜態文件