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 ...
随机推荐
- [SHOI2013]阶乘字符串
题目描述 给定一个由前\(n\)个小写字母组成的串\(S\). 串\(S\)是阶乘字符串当且仅当前\(n\)个小写字母的全排列(共\(n!\)种)都作为\(S\)的子序列(可以不连续)出现. 由这个定 ...
- P2172 [国家集训队]部落战争 二分图最小不相交路径覆盖
二分图最小不相交路径覆盖 #include<bits/stdc++.h> using namespace std; ; ; ; ], nxt[MAXM << ], f[MAXM ...
- golang map多层嵌套使用及遍历方法汇总
原文:https://blog.csdn.net/boyhandsome7/article/details/79734847 ------------------------------------- ...
- Codeforces Round #589 (Div. 2) E. Another Filling the Grid(DP, 组合数学)
链接: https://codeforces.com/contest/1228/problem/E 题意: You have n×n square grid and an integer k. Put ...
- Java对象间的关系
1 综述 在Java中对象与对象的关系总体分为四类,分别是:依赖.关联.聚合和组合. (1)依赖(Dependency)关系是类与类之间的联接.依赖关系表示一个类依赖于另一个类的定义,一般而言,依赖关 ...
- ttf-mscorefonts-installer 无法安装,解决办法
ttf-mscorefonts-installer 无法安装,解决办法 原 lieefu 发布于 2017/01/11 08:11 字数 163 阅读 1007 收藏 0 点赞 0 评论 0 面试:你 ...
- 数据类型(C++)
不同系统会有不同差异: 类型 位(byte) 范围 char 1 -128—127 or 0 – 255 unsigned char 1 0 – 255 signed int 1 -128—127 i ...
- 14.链表中倒数第k个结点 Java
题目描述 输入一个链表,输出该链表中倒数第k个结点. 思路 快指针和慢指针,快指针先跑K个单位然后慢指针开始跑,快指针跑到最后一个节点的时候慢指针对应的就是链表中倒数第k个结点 public stat ...
- mysqldump 命令
[参考文章]:mysqldump命令详解 mysql数据库中备份工具,用于将MySQL服务器中的数据库以标准的sql语言的方式导出,并保存到文件中. 1. 参数介绍 默认为 true:表示默认情况下 ...
- Linux设备驱动程序 之 主次设备号
主设备号和次设备号 对字符设备的访问是通过文件系统内的设备名称进行的,这些名称被称为特殊文件.设备文件.或者简单称之为文件系统树的节点,它们通常位于/dev目录.字符设备驱动程序的设备文件可以通过ls ...