同步线上文件到内网

#!/bin/bash                                                                                                                                             
                                                                                                                                                        
yesterday=`date -d '-1 day' +%Y%m%d`                                                                                                                    
dat=`date "+%Y-%m-%d %H:%M:%S"`                                                                                                                         
url1="http://xxx:9096/page/downFile?date=${yesterday}&fileType=2"                                                                             
url2="http://xxx:9096/page/downFile?date=$(date +%Y%m%d)&fileType=0"                                                                          
                                                                                                                                                        
REMOTE_HOST="pi1"                                                                                                                                       
FileName1="/home/ansible/temp/${yesterday}_2.txt"                                                                                                       
FileName2="/home/ansible/temp/${yesterday}_0.txt"                                                                                                       
TempPath="/home/ansible/wz-temp/pahs_api/temp"                                                                                                          
rsync_passwd="/home/ansible/wz-temp/pahs_api/conf/payhs_api.passwd"
Logfile="./logs/result.log"
ReplicatFromPi1(){

        ansible pi1 -m shell -a "curl -X GET -o /home/ansible/temp/${yesterday}_2.txt  'http://10.26.208.129:9096/page/downFile?date=${yesterday}&fileType=2' "
        if [[ $? -eq 0 ]]; then
                printf "$dat get content from ${url1} succeed.\n" >> "${Logfile}"
        else
                printf "$dat get content from ${url1} failed.\n" >> "${Logfile}"
        fi

        scp "${REMOTE_HOST}":"${FileName1}"  "${TempPath}"
        if [[ $? -eq 0 ]]; then
                printf "$dat copy ${yesterday}_2.txt from pi1 succeed.\n" >> "${Logfile}"
        else
                printf "$dat copy ${yesterday}_2.txt from pi1 failed.\n" >> "${Logfile}"
        fi

        ansible pi1 -m shell -a "curl -X GET -o /home/ansible/temp/${yesterday}_0.txt  'http://10.26.208.129:9096/page/downFile?date=${yesterday}&fileType=0' "
        if [[ $? -eq 0 ]]; then
                printf "$dat get content from ${url2} succeed.\n" >> "${Logfile}"
        else
                printf "$dat get content from ${url2} failed.\n" >> "${Logfile}"
        fi

        scp "${REMOTE_HOST}":"${FileName2}"  "${TempPath}"
        if [[ $? -eq 0 ]]; then
                printf "$dat copy ${yesterday}_0.txt from pi1 succeed.\n"  >> "${Logfile}"
        else
                printf "$dat copy ${yesterday}_0.txt from pi1 failed.\n" >> "${Logfile}"
        fi
}

RsyncItranet(){

        sudo /usr/bin/rsync -avz  --port=19873  "${TempPath}"/"${yesterday}"_*.txt   --password-file="${rsync_passwd}"   --delete payhs_user@xxxx::PayhsFile 
        if [[ $? -eq 0 ]]; then
                printf "$dat rsync to itranet host node30 succeed.\n"  >> "${Logfile}"
        else
                printf "$dat rsync to itranet host node30 failed.\n"  >> "${Logfile}"
        fi

}


main(){

        ReplicatFromPi1
        RsyncItranet

}
main

推荐阅读更多精彩内容