天天看點

通過rsync備份靜态檔案

腳本内容:

#!/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

            echo "$res is not exist"

        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

     本文轉自1321385590 51CTO部落格,原文連結:http://blog.51cto.com/linux10000/1962892,如需轉載請自行聯系原作者

繼續閱讀