linux rsync安装与使用
rsync
Usage: /etc/init.d/rsync {start|stop|reload|force-reload|restart|status}
rsync默认配置文件
# defaults file for rsync daemon mode
# start rsync in daemon mode from init.d script?
# only allowed values are "true", "false", and "inetd"
# Use "inetd" if you want to start the rsyncd from inetd,
# all this does is prevent the init.d script from printing a message
# about not starting rsyncd (you still need to modify inetd's config yourself).
RSYNC_ENABLE=false
# which file should be used as the configuration file for rsync.
# This file is used instead of the default /etc/rsyncd.conf
# Warning: This option has no effect if the daemon is accessed
# using a remote shell. When using a different file for
# rsync you might want to symlink /etc/rsyncd.conf to
# that file.
# RSYNC_CONFIG_FILE=
# what extra options to give rsync --daemon?
# that excludes the --daemon; that's always done in the init.d script
# Possibilities are:
# --address=123.45.67.89 (bind to a specific IP address)
# --port=8730 (bind to specified port; default 873)
RSYNC_OPTS=''
# run rsyncd at a nice level?
# the rsync daemon can impact performance due to much I/O and CPU usage,
# so you may want to run it at a nicer priority than the default priority.
# Allowed values are 0 - 19 inclusive; 10 is a reasonable value.
RSYNC_NICE=''
# run rsyncd with ionice?
# "ionice" does for IO load what "nice" does for CPU load.
# As rsync is often used for backups which aren't all that time-critical,
# reducing the rsync IO priority will benefit the rest of the system.
# See the manpage for ionice for allowed options.
# -c3 is recommended, this will run rsync IO at "idle" priority. Uncomment
# the next line to activate this.
# RSYNC_IONICE='-c3'
# Don't forget to create an appropriate config file,
# else the daemon will not start.
http://www.linuxidc.com/Linux/2014-09/106574.htm
rsync -h
Usage: rsync [OPTION]... SRC [SRC]... DEST
or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
or rsync [OPTION]... [USER@]HOST:SRC [DEST]
or rsync [OPTION]... [USER@]HOST::SRC [DEST]
or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect
to an rsync daemon, and require SRC or DEST to start with a module name.
-r, --recursive recurse into directories
-v, --verbose increase verbosity
-q, --quiet suppress non-error messages
--no-motd suppress daemon-mode MOTD (see manpage caveat)
-c, --checksum skip based on checksum, not mod-time & size
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
-u, --update skip files that are newer on the receiver
--inplace update destination files in-place (SEE MAN PAGE)
--append append data onto shorter files
--append-verify like --append, but with old data in file checksum
-z, --compress compress file data during the transfer
--compress-level=NUM explicitly set compression level
--skip-compress=LIST skip compressing files with a suffix in LIST
-I, --ignore-times don't skip files that match in size and mod-time
--size-only skip files that match in size
--modify-window=NUM compare mod-times with reduced accuracy
-H, --hard-links preserve hard links
-e, --rsh=COMMAND specify the remote shell to use
rsync,它比scp更强大,支持“不覆盖”原目录
例子:rsync -avz --progress /root/client/ root@202.112.23.12:/home/work/
//将本机的/root/client/拷贝至远程的202.112.23.12:/home/work/目录,--progress可以查看拷贝的过程
例子:rsync -avzu --progress /root/client/ root@202.112.23.12:/home/work/ //u选项,指定不覆盖原目录内容
我的命令`
rsync -e 'ssh -p 2330' -avzu -r --progress test root@201202:/home/work
如果主机A删除了某个文件,想要B上也删除,要加一个参数 --delete.
--delete delete extraneous files from destination dirs
--delete-before receiver deletes before transfer, not during
--delete-during receiver deletes during transfer (default)
--delete-delay find deletions during, delete after
--delete-after receiver deletes after transfer, not during
--delete-excluded also delete excluded files from destination dirs
增加--delete参数会把原有目录下的文件删除以保持客户端和服务器端文件系统完全一致,慎用.
使用rsync同步的时候,指定ssh的端口号
rsync有两种常用的认证方式,一种为rsync-daemon方式,另外一种则是ssh。
在一些场合,使用rsync-daemon方式会比较缺乏灵活性,ssh方式则成为首选。但是今天实际操作的时候发现当远端服务器的ssh默认端口被修改后,rsync时找不到一个合适的方法来输入对方ssh服务端口号。
在查看官方文档后,找到一种方法,即使用-e参数。
-e参数的作用是可以使用户自由选择欲使用的shell程序来连接远端服务器,当然也可以设置成使用默认的ssh来连接,但是这样我们就可以加入ssh的参数了。
具体语句写法如下:
- rsync -e 'ssh -p 1234' username@hostname:SourceFile DestFile
其他参数完全按照rsync的规定格式加入即可。
上面语句中比较新鲜的地方就是使用了单引号,目的是为了使引号内的参数为引号内的命令所用。没有引号的话系统就会识别-p是给rsync的一个参数了。我的描述可能比较烂,详情可以参考rsync官方描述:
Command-line arguments are permitted in COMMAND provided that COMMAND is presented to rsync as a single argument. You must use spaces (not tabs or other whitespace) to separate the command and args from each other, and you can use single- and/or double-quotes to preserve spaces in an argument (but not backslashes). Note that doubling a single-quote inside a single-quoted string gives you a single-quote; likewise for double-quotes (though you need to pay attention to which quotes your shell is parsing and which quotes rsync is parsing).
转自:http://yynotes.net/rsync-with-ssh-without-default-port/
rsync同步文件有两种方式,一种是daemon的方式(rsync daemon)另一种方式是通过远程shell方式(rsync remote shell)。
两种方式的区别
daemon方式,这种方式通过TCP方式连接远程rsync daemon,需要使用配置文件,并启用daemon进程。
rsync [OPTION] user@host::src dest
rsync [OPTION] src user@host::dest
remote shell方式,这种方式不需要使用配置文件,也不需要daemon进程。
然后是文件的增量更新,主要解决的问题是现在有两台服务器A和B,要将A服务器上的test目录增量复制到B服务器上的test目录(所谓增量更新就是指B服务器原来已经有的文件不再传了,只传送那些A有的而B没有的),这样使得B服务器上的test文件夹保持与A同步
这就需要用到rsync这个命令,这个命令的用法跟scp是一样的
比如在A服务器下执行命令:rsync -r /home/test/ user@B:/home/test 即可实现增量更新
注意:这里有一个问题需要详细说明一下:
假如test目录下有1.txt,2.txt这两个文件
如果命令中源目录那里写成这样:/home/test/
那么rsync准备更新的文件列表就是
1.txt
2.txt
然后就会在B机器的/home/test目录下找这两个文件并做增量更新,这样能够满足需求
但如果源目录写成这样:/home/test
那么rsync准备增量更新的文件列表就会是这样:
test/1.txt
test/2.txt
然后在B机器的/home/test目录下寻找test/1.txt,发现没有test文件夹,于是又创建了test文件夹,所以这样执行的结果就是B机器的目录结构就会有这两个文件,而这不是希望看到的
/home/test/test/1.txt
/home/test/test/2.txt
所以要注意这个问题。下面两种写法是正确的:
rsync -r /home/test/ user@B:/home/test
或者
rsync -r /home/test user@B:/home
具体的关于rsync的详细参数的设置这里就不说了,这里只把一种推荐的命令运行方式记录下来:
rsync -rtv /home/test/ user@B:/home/test
-t是指判断文件是否已有的时候只判断文件的时间戳和文件的大小,如果都一样就把这个文件跳过(这是一种不够严谨但足够快的方法)
-v是指输出一下执行的日志,其实可以加很多v,v越多,输出的日志越多。
参考:http://www.cnblogs.com/iforever/p/4488733.html
http://my.oschina.net/immk/blog/193926
linux rsync安装与使用的更多相关文章
- Linux Rsync
一.Rsync介绍 1.什么是Rsync Rsync 即Remote Rynchronization,是一款开源的.快速的.多功能的.可实现全量或增量的本地或者远程数据镜像同步复制.备份的优秀工具. ...
- linux rsync 实际应用
linux rsync 实际应用 一.rsync的概述 rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync.rsync是Linux系统下的文件同步和 ...
- Linux Rsync实现文件同步备份(转载)
原文地址:Linux Rsync实现文件同步备份作者:夷北 转自:http://www.mike.org.cn/blog/index.php?load=read&id=639###pp=0 [ ...
- Rsync安装部署
Rsync安装部署 1.Rsync 简介 Rsync 是一款开源的.快速的 多功能的 可以实现全量以及增量的本地或者是远程的数据同步备份的优秀工具,并且可以不进行改变原有的数据属性信息,实现数据的 ...
- Linux下安装 Posgresql 并设置基本参数
在Linux下安装Postgresql有二进制格式安装和源码安装两种安装方式,这里用的是二进制格式安装.各个版本的Linux都内置了Postgresql,所以可直接通过命令行安装便可.本文用的是Cen ...
- Linux下安装Tomcat服务器和部署Web应用
一.上传Tomcat服务器
- Linux下安装使用Solr
Linux下安装使用Solr 1.首先下载Solr.mmseg4j分词包.tomcat并解压,这用google.百度都可以搜索得到下载地址. 2.因为要使用到中文分词,所以要设置编码,进入tomcat ...
- Linux下安装tar.gz类型的jdk,并配置环境变量
近期因要学习一门技术,必须在Linux下运行,故开始学习如何使用Linux. 在安装jdk时出现了困难,环境变量配置不成功,花了一天时间才搞定,特分享出来,供大家参考. Linux下安装jdk,步骤如 ...
- Linux下安装和配置JDK与Tomcat(升级版)
在这个版本 Linux下安装和配置JDK与Tomcat(入门版) 的基础上优化升级 1.下载相关软件 apache-tomcat-6.0.37.tar.gz jdk-6u25-linux-i586-r ...
随机推荐
- Node.js 原生模块开发方式变迁
https://mp.weixin.qq.com/s/-oLqB8ITk_Q5AIoNLzBg0w
- 基于pyteseract google ocr的图形验证码识别
先灰化图片,把图片二值化,利用pytesseract包的pytesseract.image_to_string转换出文字.
- [转]ASP.NET MVC 5– 使用Wijmo MVC 5模板1分钟创建应用
开始使用 使用ComponentOne Studio for ASP.NET Wijmo制作MVC5应用程序,首先要做的是安装Studio for ASP.NET Wijmo . 测试环境 VS201 ...
- Maven配置默认使用的JDK版本
问题: 创建maven项目的时候,jdk版本是1.7版本,而自己安装的是1.8版本,从而导致无法使用lambda等Java8新特性. 每次右键项目名-maven->update project ...
- 微软Azure、谷歌GAE、亚马逊AWS比較
谷歌Google App Engine 亚马逊AWS 微软Microsoft Azure 提供服 务类型 PaaS, SaaS Iaas, PaaS IaaS, PaaS, SaaS 服务间 ...
- 如何让input number类型的标签不产生上下加减的按钮
之前用 input type="number" 来放数字框,发现有个上下加减的东西,感觉不太好 这个容易出现0 然后减为负数 这种情况下怎么去掉右边的那个上下加减的小按钮呢?前端同 ...
- LeetCode——Power of Two
Description: Given an integer, write a function to determine if it is a power of two. public class S ...
- MyBatis DAO层传递参数到mapping.xml 几种方式
Dao层传递参数到mapping.xml文件的几种方式:(Mybatis传值总结) 第一种:传递单个参数 Dao层Code片段: /** * 根据articleId查询XXXX详情. * * @par ...
- postgresql----LIKE和SIMILAR TO
LIKE和SIMILAR TO都支持模糊查询,另外SIMILAR TO还支持正则表达式查询.模糊查询中有两个重要的符号:下划线'_'匹配任意单个字符,百分号'%'匹配任意多个字符,可以是0个,如果想匹 ...
- 【NotePad++】使用指南
身为一名程序员,这绝对是很常用的工具,但是你真的用了他的全部功能么? 教程参考: [crifan 推荐]轻量级文本编辑器,Notepad 最佳替代品:Notepad++ 注:一个很详细的教程,虽然老, ...