zoukankan      html  css  js  c++  java
  • 使用rsync, 向另外一台服务器同步目录和文件的脚本

    #!/bin/bash

    #亚特兰蒂斯-同步目录
    #定时任务
    ini_file="/usr/local/sunlight/conf/rsync-file.ini"
    target_ip="10.108.144.2"
    pk_file="/usr/local/sunlight/sshkeys/init.pk"

    if [ ! -f $ini_file ];then
    echo "[ Error ] `date "+%Y/%m/%d %H:%M:%S"` $ini_file does not exist!"
    exit 1
    fi

    if [ ! -e $pk_file ];then
    echo "[ Error ] `date "+%Y/%m/%d %H:%M:%S"` $pk_file does not exist!"
    exit 1
    fi

    while read line
    do
    if [[ ! -d $line && ! -f $line ]];then
    echo "[ Error ] `date "+%Y/%m/%d %H:%M:%S"` direcoty or file: $line does not exist!"
    exit 1
    fi

    if [ ${line:0:1} != "/" ];then
    echo " [ Error ] $line must start with /"
    exit 1
    fi

    if [[ -d $line && ${line:0-1:1} != "/" ]];then
    line="$line/"
    fi

    if [ -d $line ];then
    ssh -p2222 -i /usr/local/sunlight/sshkeys/init.pk -o strictHostKeyChecking=no $target_ip "test -d $line || mkdir -p $line"
    fi

    if [ -f $params ];then
    param_dir=${line%/*}
    ssh -p2222 -i /usr/local/sunlight/sshkeys/init.pk -o strictHostKeyChecking=no $target_ip "test -d $param_dir || mkdir -p $param_dir"
    fi

    echo "rsync $line......"
    rsync -avztog --progress -e "ssh -p2222 -i /usr/local/sunlight/sshkeys/init.pk -o strictHostKeyChecking=no" ${line} ${target_ip}:${line}

    done < $ini_file

  • 相关阅读:
    Supervisor安装与使用
    windows常用快捷键和指令
    搜索引擎使用技巧
    golang核心Goroutine和channel
    4、小程序原生底部菜单
    三、小程序值使用vant开发
    axios请求2
    3、小程序消息推送
    居中
    一、底部菜单
  • 原文地址:https://www.cnblogs.com/ralphdc/p/8109847.html
Copyright © 2011-2022 走看看