数据同步

#!/bin/bash
# Auther: Dusk

if  [ $# -ne 1 ];then
   echo "Usage: $0 /path/to/file(绝对路径)"
   exit
fi 

if [ ! -e $1 ];then
    echo "[ $1 ] dir or file not find!"
    exit
fi

fullpath=`dirname $1`

basename=`basename $1`

cd $fullpath

k8s_host_list=(k8s77 k8s88 k8s99)			# 本地 host 配置对应 IP和名称

for host in ${k8s_host_list[@]};do
  tput setaf 2
    echo ===== rsyncing ${host}: $basename =====
    tput setaf 7
    rsync -az $basename  `whoami`@${host}:$fullpath
    if [ $? -eq 0 ];then
      echo "命令执行成功!"
    fi
done


chmod +x /usr/local/sbin/data_rsync.sh
posted @ 2024-08-19 22:54  Dusk_Yun  阅读(12)  评论(0)    收藏  举报