• 使用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

  • 相关阅读:
    Jenkins的maven工程打包的时候怎么指定不同环境的配置文件
    杂记待整理
    zabbix监控网络的出入口流量
    MySQL的恢复脚本
    mysql 备份恢复图
    切割haproxy的日志
    zabbix 监控MySQL
    svn 的备份还原
    svn做目录访问控制(AuthzSVNAccessFile)
    MySQL多实例
  • 原文地址:https://www.cnblogs.com/ralphdc/p/8109847.html
Copyright © 2020-2023  润新知