上传到不同服务器脚本

一个分片上传的脚本:

#!/bin/sh

source ./shard.properties

for i in {0..7}
do
    echo "[`date`] scp $i start"

    targetUrlPath=`eval echo '$'"shard${i}"`


    host=$(echo $targetUrlPath|awk -F ':' '{print $1}')
    targetPath=$(echo $targetUrlPath|awk -F ':' '{print $2}')
    uploadPath=`eval echo $targetPath|awk -F '/'  '{newPath=substr($0,0,length($0)-length($(NF-1))-1);print newPath"bak";}'`
    remoteCmd=`eval echo mkdir -p $uploadPath`
 
       ssh $host   `eval echo $remoteCmd`
       
    scp -o StrictHostKeyChecking=no -l 400000 externalhour/shard/${i}/external_adproduct  ${host}:${uploadPath}/.


    remoteMvCmd=`eval echo mv  ${uploadPath}/external_adproduct ${targetPath}external_adproduct`
    echo ${remoteMvCmd}
    ssh $host   "${remoteMvCmd}"
    

    echo "[`date`] mv  end"
done

分片配置文件:

shard0=xx.xx.xx.xx:/home/search/data0/
shard1=xx.xx.xx.xx:/home/search/data0/
shard2=xx.xx.xx.xx:/home/search/data0/
shard3=xx.xx.xx.xx:/home/search/data0/
shard4=xx.xx.xx.xx:/home/search/data0/
shard5=xx.xx.xx.xx:/home/search/data0/
shard6=xx.xx.xx.xx:/home/search/data0/
shard7=xx.xx.xx.xx:/home/search/data0/


服务器文件为ip列表:

172.1.1.1
172.1.1.2
172.1.1.3
地址固定,可这么写 :

#!/bin/sh

#要更新的文件
fileName=xx
#机器列表
for line in `cat ips.txt` 
do
    host=$line
    #目标路径
    targetPath="~/xx/"
    #备份路径
    bakPath="~/xx/bak/"
    #创建备份路径命令
    bakCmd="mkdir -p $bakPath"

    

    #创建备份路径
    ssh $host   $bakCmd

    #备份文件后缀名
    bakSuffix=".`date +%Y%m%d_%H%M%S`"
    #远程备份命令
    remoteBakCmd="cp  ${targetPath}/${fileName} ${bakPath}/${fileName}${bakSuffix}"
    #执行备份命令
    ssh $host   $remoteBakCmd
    
    #上传文件
    scp -o StrictHostKeyChecking=no -l 400000 ${fileName}  ${host}:${targetPath}/${fileName}
    
done

文/程忠 浏览次数:0次   2020-07-20 21:44:02

相关阅读


评论:
点击刷新

↓ 广告开始-头部带绿为生活 ↓
↑ 广告结束-尾部支持多点击 ↑