rsync同步脚本
#!/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同步脚本的更多相关文章
- shell脚本 inotify + rsync 同步脚本
1.这是很简单的一个 文件监控+触发同步脚本 监控一台服务器下的一个文件夹,发生改变则向另一个个文件夹进行同步. 具体的inotify命令 rsync命令 可以看linux分类下的介绍 inoti ...
- shell生成rsync同步脚本
test #!/bin/bash # # Rsync Install Script # Last Updated # ##### modify by Jinayf ##### ######手动修改以下 ...
- Windows Linux 之间rsync同步CODE文件
Windows Linux 之间rsync同步CODE文件 一.环境Windows:OS:Microsoft Windows Web Server 2008 SP1IP:192.168.88.197 ...
- rsync同步Nginx日志遇到问题总结
一.目的 将nginx 日志通过普通用户利用rsync公钥认证的方式实时同步到本地服务器上,之后使用elk程序进行处理. 二.遇到问题及解决方法思路 问题1.文件权限:nginx 的日志默认权限如下: ...
- Linux rsync 同步实践
目录[-] 1. rsync 同步的大致思路 2. rsync的安装 3. rsync的配置 4. rsync的基本操作 服务器端启动 注2. 实时同步 注3. rsync通过linux防火墙 公司网 ...
- Ubuntu下多服务器 Rsync同步镜像服务配置
主服务器:192.168.5.13_ubuntu 从服务器:192.168.5.11_centos ================== 1> 在两台主机上分别安装rsync========== ...
- Windows 之间用rsync同步数据(cwRsyncServer配置)
rsync是一款优秀的数据同步软件,在跨服务器,跨机房,跨国备份服务器的首选工具,下面就来介绍下如何配置安装cwRsyncServer很大多数软件一样是B/C架构,cwRsyncServer是rsyn ...
- Linux下inotify监控文件夹状态,发生变化后触发rsync同步
1.安装工具--inotifywget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar ...
- rsync同步目录及同步文件
最简单的只读同步工作. 一,服务端的配置 1,安装rsync(阿里云默认已有此程序) 略 2,生成文件rsyncd.conf,内容如下: #secrets file = /etc/rsyncd.sec ...
随机推荐
- Some ML Tutorials
VAE: What-is-variational-autoencoder-vae-tutorial Variational-autoencoders-explained Building variat ...
- python 套接字Socket详解
socket简介 1. 什么是socket ? socket(简称 套接字) 是进程间通信的一种方式,它与其他进程间通信的一个主要不同是: 它能实现不同主机间的进程间通信,我们网络上各种各样的服务大多 ...
- idea目录因包名而未合并、逐级显示的问题
如图包名里含有多个.,从而导致一个加载时出现了好多层.. 只要右键java目录,转换为source root就行.
- ProjectEuler215 Crack-free Walls
易知状态不会太多(\(3329\)个),直接搜一下,按照能不能连在后面建边,跑一遍dp即可 #include <bits/stdc++.h> using namespace std; st ...
- RunTime.getRunTime().addShutdownHook 添加钩子
Runtime.getRuntime().addShutdownHook(shutdownHook); google了一下它的含义:在jvm中增加一个关闭的钩子,当jvm关闭的时候,会执行系统中已经设 ...
- 关于iar intrinsics.h is already included previously!报错的问题及解决办法
用最新的cubemx生成f103的代码(带freertos系统),如果用iar编译,可能会出现intrinsics.h is already included previously!的错误,如果没有待 ...
- 爬当当网上python书籍的图片
1.分析网页代码,获取图片下载连接:http://img3m4.ddimg.cn/20/11/23473514-1_b_5.jpg 2. python实现代码 import os import re ...
- 【方法】JS判断当前页面环境:PC端/移动端,安卓/IOS,微信环境/QQ环境等等
[主要知识] 浏览器设备信息:navigator.userAgent(本文中主要用到知识) 浏览器版本信息:navigator.appVersion var ua = navigator.userAg ...
- HDU 5936 Difference ( 2016 CCPC 杭州 D && 折半枚举 )
题目链接 题意 : 给出一个 x 和 k 问有多少个 y 使得 x = f(y, k) - y .f(y, k) 为 y 中每个位的数的 k 次方之和.x ≥ 0 分析 : f(y, k) - y = ...
- ETL测试场景和测试用例设计
前段时间做了些数据测试相关的工作,找了些相关方面的资料,也跟一些一线厂的同学聊了下数据测试方面的东西,然后在团队内部形成了一个初级的数据测试的规范流程以及测试需要进行的场景设计和测试用例设计的方案. ...