#!/bin/bash
export LANG=C date=`date +%Y-%m-%d-%H%M` red=`echo -e "\033[0;31m"`
blue=`echo -e "\033[0;36m"`
white=`echo -e "\033[37m"` rsync=/usr/bin/rsync
rsync_bak_dir=/opt/data_bak/rsync_update_bak
exclude_web_file=/root/sh/rsync_online_web/exclude_web_file.txt
exclude_res_file=/root/sh/rsync_online_web/exclude_res_file.txt
www_bak_dir=/opt/data_bak/rsync_update_bak/www/$date
res_bak_dir=/opt/data_bak/rsync_update_bak/res/$date
logs=/var/log/rsync_web #删除历史备份函数
del_rsync_history(){
del_rsync_history=${rsync_bak_dir:?error} #删除历史目录是否定义,如果未定义程序退出,不在往下执行。
if [ $del_rsync_history != "/opt/data_bak/rsync_update_bak" ];then #判断删除历史目录是否正确,避免误删除
printf $red
echo "$del_rsync_history File directory error !!!"
echo "Exit..."
sleep
printf $white
exit
fi echo "find $del_rsync_history -mtime +30 | xargs rm -rf"
find $del_rsync_history -mtime + | xargs rm -rf
} #同步是否成功函数
is_ok(){
if [ $? -eq ];then
printf $blue
echo "file update Success"
printf $white
else
printf $blue
echo "file update Fail !!!"
printf $white
fi
} #同步排除文件是否存在函数
file_web_exist(){
if [ ! -f $exclude_web_file ];then
printf $red
echo "$exclude_web_file file does not exist !!!"
printf $white
exit
fi
} file_res_exist(){
if [ ! -f $exclude_res_file ];then
printf $red
echo "$exclude_res_file file does not exist !!!"
printf $white
exit
fi
} #日志目录是否存在
if [ ! -d $logs ];then
mkdir -p $logs
fi #目标文件夹
target_www=/opt/web/test/
target_res=/opt/web/test/res/ ip=192.168.1.100
user=rsyncuser
pass=/root/sh/rsync_online_web/rsyncpass #源文件夹
source_www=$user@$ip::web_www
source_res=$user@$ip::web_res #同步流程
if [ "$1" = "www" ];then
file_web_exist #判断同步排除文件是否存在
$rsync -vzrtopg \
-n \
--progress \
--delete-after \
--exclude-from=$exclude_web_file \
--password-file=$pass \
$source_www $target_www printf $blue
echo "-----------------------------------------------------"
echo " Are you sure update www.test.com ?[Y/y]"
echo "-----------------------------------------------------"
printf $white
read -p "> " s
if [ $s == "Y" -o $s == "y" ];then if [ ! -d $www_bak_dir ];then
mkdir -p $www_bak_dir
fi $rsync -vzrtopg \ #同步参数,-v显示详细信息,-z传输文件压缩,-r递归模式,-t保持文件时间信息,-o保持文件属主信息,-p保持文件权限,-g保持文件组信息
--progress \ #显示rsync备份过程
--delete-after \ #同步后删除文件
--exclude-from=$exclude_web_file \ #排除文件列表
--backup \ #备份
--backup-dir=$www_bak_dir \ #备份目录
--log-file=$logs/www.test.com.log \ #日志文件
--log-file-format="%f" \ #日志格式
--password-file=$pass \ #rsync密码
$source_www $target_www #将source_www文件及目录同步到target_www目录
is_ok #判断是否同步成功函数
del_rsync_history #删除历史备份文件函数
else
printf "No choice,Exit...\n"
exit
fi elif [ "$1" = "res" ]; then
file_res_exist
$rsync -vzrtopg \
-n \
--progress \
--delete-after \
--exclude-from=$exclude_res_file \
--password-file=$pass \
$source_res $target_res printf $blue
echo "-----------------------------------------------------"
echo " Are you sure update res.test.com ?[Y/y]"
echo "-----------------------------------------------------"
printf $white
read -p "> " s
if [ $s == "Y" -o $s == "y" ];then if [ ! -d $res_bak_dir ];then
mkdir -p $res_bak_dir
fi $rsync -vzrtopg \
--progress \
--delete-after \
--exclude-from=$exclude_res_file \
--backup \
--backup-dir=$res_bak_dir \
--log-file=$logs/res.test.com.log \
--log-file-format="%f" \
--password-file=$pass \
$source_res $target_res
is_ok
del_rsync_history
else
printf "No choice,Exit...\n"
exit
fi else
echo "----------------------------------------------------------------------------------------"
printf $blue
printf "\twww.test.com\n"
printf "\tUsage: /root/sh/rsync_online_web/rsync_test_web_update.sh {www|res}\n"
printf $white
echo "----------------------------------------------------------------------------------------"
fi

rsync同步脚本的更多相关文章

  1. shell脚本 inotify + rsync 同步脚本

    1.这是很简单的一个 文件监控+触发同步脚本 监控一台服务器下的一个文件夹,发生改变则向另一个个文件夹进行同步. 具体的inotify命令  rsync命令  可以看linux分类下的介绍 inoti ...

  2. shell生成rsync同步脚本

    test #!/bin/bash # # Rsync Install Script # Last Updated # ##### modify by Jinayf ##### ######手动修改以下 ...

  3. Windows Linux 之间rsync同步CODE文件

    Windows Linux 之间rsync同步CODE文件 一.环境Windows:OS:Microsoft Windows Web Server 2008 SP1IP:192.168.88.197 ...

  4. rsync同步Nginx日志遇到问题总结

    一.目的 将nginx 日志通过普通用户利用rsync公钥认证的方式实时同步到本地服务器上,之后使用elk程序进行处理. 二.遇到问题及解决方法思路 问题1.文件权限:nginx 的日志默认权限如下: ...

  5. Linux rsync 同步实践

    目录[-] 1. rsync 同步的大致思路 2. rsync的安装 3. rsync的配置 4. rsync的基本操作 服务器端启动 注2. 实时同步 注3. rsync通过linux防火墙 公司网 ...

  6. Ubuntu下多服务器 Rsync同步镜像服务配置

    主服务器:192.168.5.13_ubuntu 从服务器:192.168.5.11_centos ================== 1> 在两台主机上分别安装rsync========== ...

  7. Windows 之间用rsync同步数据(cwRsyncServer配置)

    rsync是一款优秀的数据同步软件,在跨服务器,跨机房,跨国备份服务器的首选工具,下面就来介绍下如何配置安装cwRsyncServer很大多数软件一样是B/C架构,cwRsyncServer是rsyn ...

  8. Linux下inotify监控文件夹状态,发生变化后触发rsync同步

    1.安装工具--inotifywget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar ...

  9. rsync同步目录及同步文件

    最简单的只读同步工作. 一,服务端的配置 1,安装rsync(阿里云默认已有此程序) 略 2,生成文件rsyncd.conf,内容如下: #secrets file = /etc/rsyncd.sec ...

随机推荐

  1. SVN建立分支和合并代码

    1.SVN建立分支正确SVN服务器上会有两个目录:trunk和branches.trunk目录下面代码就是所谓的主版本,而branches文件夹主要是用来放置分支版本.分支版本是依赖于主版本的,因此建 ...

  2. Layui 内置方法 - layer.prompt_(输入层)

    prompt的参数也是向前补齐的.options不仅可支持传入基础参数,还可以传入prompt专用的属性.当然,也可以不传,yes携带value 表单值index 索引elem 表单元素. promp ...

  3. HTML5新特性——1 HTML5音频

    注意:<source>同一个音乐可以添加不同格式的音频,这样就可以满足不同浏览器都能够正常播放,兼容不同浏览器. 代码示例: <!doctype html> <html ...

  4. 【高维前缀和】8.15B. 组合数

    题目分析 没有接触过高维前缀和的话会有一点抽象

  5. vue项目环境的搭建

    首先要明白Vue是基于node的,在公司要使用vue来开发项目的话肯定是要先安装node的,下面是搭建一个最简单的vue项目环境 一 安装node 这个可以去node的官网下载对应版本 安装好之后 c ...

  6. MyBatis注解Annotation介绍及Demo(转)

    MyBatis可以利用SQL映射文件来配置,也可以利用Annotation来设置.MyBatis提供的一些基本注解如下表所示. 注解 目标 相应的XML 描述 @CacheNamespace 类 &l ...

  7. OFDM发端硬件实现原理图

    OFDM时域削峰法的详细说明可参考:https://www.cnblogs.com/achangchang/p/11037498.html

  8. OFDM留空中央直流子载波目的及原理

    目的: 降低峰均比! 原理: IDFT公式: 直流分量k接近0,公式近似于对X(k)进行累加,因此直流分量会产生较大的信号能量,造成严重的峰均比. 详细内容可参考: https://dwz.cn/Zl ...

  9. apply, bind, call--绑定this的方法

    Function.prototype.call(),Function.prototype.apply(),Function.prototype.bind() 是三种改变函数内部this指向(即函数执行 ...

  10. 如何复制word的图文到ueditor中自动上传?

    官网地址http://ueditor.baidu.com Git 地址 https://github.com/fex-team/ueditor 参考博客地址 http://blog.ncmem.com ...