Rsync多模块复制、排除指定文件及目录以及数据无差异复制的应用实例
在我的博客《Rsync 数据复制软件应用》中,拉取数据访问的都是服务器端的/backup 目录,当然我们在其他目录下拉取数据。而实现这种操作就是指多模块复制。
要实现多模块复制首先需要修改rsync的配置文件rsyncd.conf(要记得此处的配置文件在服务器端哦!)
[root@localhost ~]# vim /etc/rsyncd.conf
[root@localhost ~]# cat /etc/rsyncd.conf
#rsync_config____________________start
#created by wj root
uid=rsync
gid=rsync
fake super = yes
use chroot = no
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/run/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 192.168.146.0/24
hosts deny =0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
comment = welcome to backup!
path = /backup/
[data] #加入的内容
path = /data/
建立并授权目录
[root@localhost ~]# mkdir -p /data
[root@localhost ~]# chown -R rsync.rsync /data
[root@localhost ~]# ls -ld /data
drwxr-xr-x. 2 rsync rsync 6 5月 5 15:47 /data
重启Rsync服务(只要修改过配置文件,就要重启服务)
[root@localhost ~]# systemctl restart rsyncd
现在就可以从客户端访问测试了
[root@web1 ~]# rsync -avz /wjtest rsync_backup@192.168.146.100::data
Password:
@ERROR: auth failed on module data
rsync error: error starting client-server protocol (code 5) at main.c(1649) [sender=3.1.2] #出现这种情况是由于服务端的验证账户密码输入错误导致的,一定要输入正确的密码
[root@web1 ~]# rsync -avz /wjtest rsync_backup@192.168.146.100::data
Password:
sending incremental file list
wjtest/
wjtest/wj.txt
sent 123 bytes received 47 bytes 37.78 bytes/sec
total size is 0 speedup is 0.00
[root@web1 ~]#
登录服务端验证
[root@localhost ~]# ls /data
wjtest
排除指定目录和文件的数据复制
注意首先我们需要在服务器端创建测试文件与目录
[root@localhost backup]#mkdir {a..d}
[root@localhost backup]#touch a/1 b/2 c/3 d/4
[root@localhost backup]# tree /backup/
/backup/
├── a
│ └── 1
├── b
│ └── 2
├── c
│ └── 3
└── d
└── 4
4 directories, 4 files
我创建人四个目录a、b、c、d,目录下分别存放1、2、3、4,其中/backup目录为Rsync服务器端指定的备份同步目录
以在Rsync客户端(192.168.146.110)上执行拉取文件操作,及从服务器端同步文件到客户端
在同步数据过程中,假设要排除a、c目录(包括下面的文件)及b目录下的2文件
[root@web1 ~]# ls -l /mnt
总用量 0
[root@web1 ~]# rsync --exclude=a --exclude=b/2 --exclude=c -avzrtopgP \ rsync_backup@192.168.146.100::backup/ /mnt --password-file=/etc/rsync.password #注意这里不需要空格,有空格会出错的
@ERROR: auth failed on module backup
rsync error: error starting client-server protocol (code 5) at main.c(1649) [Receiver=3.1.2]
[root@web1 ~]# rsync --exclude=a --exclude=b/2 --exclude=c -avzrtopgP \rsync_backup@192.168.146.100::backup/ /mnt --password-file=/etc/rsync.password
receiving incremental file list
./
b/
d/
d/4
0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/4)
sent 81 bytes received 175 bytes 512.00 bytes/sec
total size is 0 speedup is 0.00
[root@web1 ~]#
在客户端查看
[root@web1 ~]# tree /mnt
/mnt
├── b
└── d
└── 4
2 directories, 1 file
主机之间数据无差异复制
要实现这种同步方式就要使用Rsync的参数--delete,所谓无差异复制,就是不管是拉取还是推送,都要保持两边的数据完全一致。
本地推送式删除如下
[root@web1 ~]# mkdir null
[root@web1 ~]# rsync -avzP --delete null/ /mnt/
sending incremental file list
deleting d/4
deleting d/
deleting b/
./
sent 43 bytes received 38 bytes 162.00 bytes/sec
total size is 0 speedup is 0.00
检查/mnt中文件是否被删除
[root@web1 ~]# tree /mnt
/mnt
0 directories, 0 files
拉取式数据无差异同步方式
[root@web1 ~]# rsync -avz --delete rsync_backup@192.168.146.100::backup /wjtest/ --password-file=/etc/rsync.password
receiving incremental file list
deleting wj.txt
./
a/
a/1
b/
b/2
c/
c/3
d/
d/4
sent 123 bytes received 363 bytes 972.00 bytes/sec
total size is 0 speedup is 0.00
查看/wjtest
[root@web1 ~]# ls /wjtest
a b c d
登录到服务端服务器查看/kackup
[root@localhost mnt]# ls /backup
a b c d
发现此刻,在服务端服务器/kackup与客户端服务器 /wjtest目录下的文件一致
Rsync多模块复制、排除指定文件及目录以及数据无差异复制的应用实例的更多相关文章
- find tar排除指定文件或目录操作及查找文件内容关键字
1.find查找排除单个目录 查找当前目录或者子目录下所有.txt文件,但是跳过子目录sk find . -path "./sk" -prune -o -name "*. ...
- Linux tar命令exclude选项排除指定文件或目录
在linux中可以用tar打包目录以方便传输or备份,我们先来看一个例子 test 文件夹有如下文件 [root@lee ~]# ll test 总用量 -rw-r--r--. root root 4 ...
- web站点和windows服务项目发布时如何排除指定文件
在发布asp.net站点和windows服务项目时,有的时候这样的需求:msbuild编译之后发布到服务器指定目录时要排除指定文件,比如通过jenkins构建时,不希望覆盖原来的Web.config和 ...
- 【测试技术】ant在测试中的使用@文件以及目录的读写删和复制
ant其实就是一个java的打包工具,存在的时间已经很久了,很多同行在使用中可能就是用,对为什么要用它,能够怎么用没有更多的了解: ---------------------------------- ...
- [转]C# FileSystemWatcher监控指定文件或目录的文件的创建、删除、改动、重命名等活动
觉得这个很常用..比如一些软件. http://www.rabbit8.cn/DoNet/407.html FileSystemWatcher控件主要功能: 监控指定文件或目录的文件的创建.删 ...
- java实现指定文件扫描目录
package com.miss.time1230.io; import java.io.File; import java.util.Scanner; /** * @author MISS * 描述 ...
- rm排除指定文件或指定文件夹下文件
3.方法3,当前文件夹中结合使用grep和xargs来处理文件名: ls | grep -v keep | xargs rm #删除keep文件之外的所有文件 说明: ls先得到当前的所有文件和文件夹 ...
- 使用VS的生成事件命令行指令将生成的exe,dll文件复制到指定文件夹中
VS预生成事件命令行 和 生成后事件命令行 宏说明 $(ConfigurationName) 当前项目配置的名称(例如,“Debug|Any CPU”). $(OutDir) ...
- 第十九章 Python os模块,pathlib 判断文件是目录还是文件
OS模块 os.path.abspath() :返回path规范化的绝对路径 import sys import os BASE_DIR = os.path.dirname(os.path.dirna ...
随机推荐
- javascript中的模块系统
目录 简介 CommonJS和Nodejs AMD异步模块加载 CMD ES modules和现代浏览器 在HTML中使用module和要注意的问题 简介 在很久以前,js只是简单的作为浏览器的交互操 ...
- LeetCode1576. 替换所有的问号
原题链接 1 class Solution { 2 public: 3 string modifyString(string s) { 4 int lens = s.length(); 5 for(i ...
- mysql索引设计的注意事项(大量示例,收藏再看)
mysql索引设计的注意事项(大量示例,收藏再看) 目录 一.索引的重要性 二.执行计划上的重要关注点 (1).全表扫描,检索行数 (2).key,using index(覆盖索引) (3).通过ke ...
- 微信小程序onReachBottom第二次失效
当整个页面就是一个view包着一个轮播.一个横向scroll-view和一个纵向scroll-view onReachBottom方法只执行一次 解决方法:
- JS时间格式转成字符串
formatNumber = n => { n = n.toString(); return n[1] ? n : '0' + n }; // 时间格式化 formatTime = date = ...
- div中如何让文本元素、img元素水平居中且垂直居中
一.文本元素在div中的水平居中且垂直居中方法 html代码 <div id="box"> <p>文本元素</p> </div> c ...
- 最简要的Dubbo文档
1.Dubbo是什么? Dubbo是阿里巴巴开源的基于 Java 的高性能 RPC 分布式服务框架,现已成为 Apache 基金会孵化项目. 面试官问你如果这个都不清楚,那下面的就没必要问了. 官网: ...
- 时间同步chrony,最全最细
时间同步服务 多主机协作工作时,各个主机的时间同步很重要,时间不一致会造成很多重要应用的故障,如:加密协 议,日志,集群等, 利用NTP(Network Time Protocol) 协议使网络中的各 ...
- Python基础之数据类型详解
为什么会有数据类型? 在介绍具体的数据类型之前,需要了解为什么需要区分数据类型.我们知道,一个公司会有很多个大的部门,每个部门下又会有许多细分的小部门,构成了公司的完整体系结构.如果把python的数 ...
- java例题_22 用递归求阶乘 5!
1 /*22 [程序 22 递归求阶乘] 2 题目:利用递归方法求 5!. 3 程序分析:递归公式:fn!=fn*4! 4 */ 5 6 /*分析 7 * 递归:如果其中每一步都要用到前一步或前几步的 ...