xsync 集群同步脚本「建议收藏」

xsync 集群同步脚本「建议收藏」scp和rsync均是远程拷贝,rsync远程分发xsync集群分发脚本循环复制文件到所有节点相同的目录下新建一个脚本touchxsync.shvimxsync.sh#!/bin/bash#$#:表示传递给脚本或函数的参数个数。#1获取输入参数个数,如果没有参数,直接退出pcount=$#if((pcount==0));thenechonoargs…

大家好,又见面了,我是你们的朋友全栈君。

scp 和rsync均是远程拷贝,

rsync 远程分发

在这里插入图片描述

在这里插入图片描述

xsync 集群分发脚本

循环复制文件到所有节点相同的目录下

新建一个脚本

touch xsync.sh
vim xsync.sh
#!/bin/bash
# $#:表示传递给脚本或函数的参数个数。
#1 获取输入参数个数,如果没有参数,直接退出
pcount=$#
if((pcount==0)); then
echo no args;
exit;
fi
 
#2 获取文件名称
p1=$1
fname=`basename $p1`
echo fname=$fname
 
#3 获取上级目录到绝对路径
pdir=`cd -P $(dirname $p1); pwd`
echo pdir=$pdir
 
#4 获取当前用户名称
user=`whoami`
 
#5 循环
#for((host=0; host<5; host++)); do
        #echo $pdir/$fname $user@192.168.3.15$host:$pdir
 #       echo --------------- 192.168.3.15$host ----------------
 #       rsync -rvl $pdir/$fname $user@192.168.3.15$host:$pdir
#done
 
#5 循环
for host in { 
   master,slaver1,slaver2,slaver3,slaver4,slaver5}; do
        #echo $pdir/$fname $user@$host:$pdir
        echo --------------- $host ----------------
        rsync -rvl $pdir/$fname $user@$host:$pdir
done

赋予执行权限

chmod 777 xsync.sh

测试
同步一个文件夹

 cd /usr/local/
 xsync.sh hive

执行结果

[root@master local]# xsync.sh hive
fname=hive
pdir=/usr/local
--------------- master ----------------
sending incremental file list

sent 53 bytes  received 17 bytes  28.00 bytes/sec
total size is 0  speedup is 0.00
--------------- slaver1 ----------------
sending incremental file list

sent 49 bytes  received 17 bytes  44.00 bytes/sec
total size is 0  speedup is 0.00
--------------- slaver2 ----------------
sending incremental file list
hive/

sent 52 bytes  received 20 bytes  48.00 bytes/sec
total size is 0  speedup is 0.00
--------------- slaver3 ----------------
sending incremental file list
hive/

sent 52 bytes  received 20 bytes  48.00 bytes/sec
total size is 0  speedup is 0.00
--------------- slaver4 ----------------
sending incremental file list
hive/

sent 56 bytes  received 20 bytes  50.67 bytes/sec
total size is 0  speedup is 0.00
--------------- slaver5 ----------------
sending incremental file list
hive/

sent 52 bytes  received 20 bytes  48.00 bytes/sec
total size is 0  speedup is 0.00
[root@master local]# 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/137335.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号