#!/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. 用idea操作svn

    使用SVN前提必须安装好服务端和客户端,或者知道服务端的url才能对服务器中的文件进行操作. 服务端:SVN service 客户端:TortoiseSVN 提交 第一步:确认SVN 服务器是否开启 ...

  2. summernote 富文本编辑器限制输入字符长度

    项目中需要一个比较简单的富文本编辑器,于是选中了summernote .虽然比较轻量,但是在开发中也遇到了几个问题,在此记录一下. 1:样式和bootstrap冲突,初始化之后显示为: .note-e ...

  3. Spring事务管理----------整合学习版

    作者:学无先后 达者为先 Spring提供了一流的事务管理.在Spring中可以支持声明式事务和编程式事务. 一  spring简介 1 Spring的事务       事务管理在应用程序中起着至关重 ...

  4. codeblock的一个小问题

    也许不叫问题吧,也可能是编译器的特性. 我的codeblock选择的编译器: 编写.cpp文件时,floatl类型输入输出都是 %f,double类型输入只能是 %lf,输出只能是 %f. 但是在co ...

  5. springboot整合easyexcel实现Excel导入导出

    easyexcel:快速.简单避免OOM的java处理Excel工具 Java解析.生成Excel比较有名的框架有Apache poi.jxl.但他们都存在一个严重的问题就是非常的耗内存,poi有一套 ...

  6. 调用jquery.Jcrop.min.js 切割图片 实例

    需求是:上传一个图片,然后将上传的这个图片进行切割........ 首先是jsp页面.页面需要引入js  <script src="${fileUrlPrx}/scripts/wap/ ...

  7. ThinkPHP,page,paginate后台分页翻页时保留检索条件的方法

    paginate(20,false,['query'=>request()->param()]);   20是每页显示行数 示例代码:  $list = Db::name('article ...

  8. 【luoguP1955 】[NOI2015]程序自动分析--普通并查集

    题目描述 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3...代表程序中出现的变量,给定n个形如xi=xj或xi≠xj的变 ...

  9. delphi将两个Strlist合并,求并集

    Function StrList_Merge(StrListA,StrListB:String):String; //将两个Strlist合并,求并集 var SListA,SListB,SListC ...

  10. neo4j︱与python结合的py2neo使用教程

    —- 目前的几篇相关:—– neo4j︱图数据库基本概念.操作罗列与整理(一) neo4j︱Cypher 查询语言简单案例(二) neo4j︱Cypher完整案例csv导入.关系联通.高级查询(三) ...