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的参数了。

具体语句写法如下:

  1. 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安装与使用的更多相关文章

  1. Linux Rsync

    一.Rsync介绍 1.什么是Rsync Rsync 即Remote Rynchronization,是一款开源的.快速的.多功能的.可实现全量或增量的本地或者远程数据镜像同步复制.备份的优秀工具. ...

  2. linux rsync 实际应用

    linux rsync 实际应用 一.rsync的概述 rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync.rsync是Linux系统下的文件同步和 ...

  3. Linux Rsync实现文件同步备份(转载)

    原文地址:Linux Rsync实现文件同步备份作者:夷北 转自:http://www.mike.org.cn/blog/index.php?load=read&id=639###pp=0 [ ...

  4. Rsync安装部署

    Rsync安装部署 1.Rsync  简介 Rsync  是一款开源的.快速的 多功能的 可以实现全量以及增量的本地或者是远程的数据同步备份的优秀工具,并且可以不进行改变原有的数据属性信息,实现数据的 ...

  5. Linux下安装 Posgresql 并设置基本参数

    在Linux下安装Postgresql有二进制格式安装和源码安装两种安装方式,这里用的是二进制格式安装.各个版本的Linux都内置了Postgresql,所以可直接通过命令行安装便可.本文用的是Cen ...

  6. Linux下安装Tomcat服务器和部署Web应用

    一.上传Tomcat服务器

  7. Linux下安装使用Solr

    Linux下安装使用Solr 1.首先下载Solr.mmseg4j分词包.tomcat并解压,这用google.百度都可以搜索得到下载地址. 2.因为要使用到中文分词,所以要设置编码,进入tomcat ...

  8. Linux下安装tar.gz类型的jdk,并配置环境变量

    近期因要学习一门技术,必须在Linux下运行,故开始学习如何使用Linux. 在安装jdk时出现了困难,环境变量配置不成功,花了一天时间才搞定,特分享出来,供大家参考. Linux下安装jdk,步骤如 ...

  9. Linux下安装和配置JDK与Tomcat(升级版)

    在这个版本 Linux下安装和配置JDK与Tomcat(入门版) 的基础上优化升级 1.下载相关软件 apache-tomcat-6.0.37.tar.gz jdk-6u25-linux-i586-r ...

随机推荐

  1. Oracle Apex 有用笔记系列 2 - 文件上传管理

    1. 页面设计 页面A有若干region, 当中一个region用于文件列表管理(包含显示,下载.删除).如图A. 在页面A有一button,点击它会调用页面B,页面B负责文件上传.如图B. 图A 图 ...

  2. lodash(二)对象+循环遍历+排序

    前言: lodash(一)中只是研究了array中的多种方法,接下来就是经常用到的循环遍历问题 过程: 1._.forEach(collection, [iteratee=_.identity], [ ...

  3. Android 基于帧布局实现一个进度条 FrameLayout+ProgressBar

    在FrameLayout中添加一个ProgressBar居中 <ProgressBar android:layout_gravity="center" android:id= ...

  4. Android 使用RadioGroup和RadioButton实现单选效果

    RadioButton和CheckBox的区别:CheckBox选中之后可以直接取消,RadioButton选中之后不能直接取消,所以一般情况下不建议单独使用.1.RadioGroup:RadioBu ...

  5. linux的setup命令设置网卡和防火墙等

    以前在centos上配置网卡都是纯命令行,今天发现linux原来还有一个setup那么好用的命令,真是相见恨晚,以后防火墙.网卡.其他网络配置.系统配置(开机启动项)都可用他来完成了

  6. PHP之命名空间

    前面的话 从广义上来说,命名空间是一种封装事物的方法.在很多地方都可以见到这种抽象概念.例如,在操作系统中目录用来将相关文件分组,对于目录中的文件来说,它就扮演了命名空间的角色.这个原理应用到程序设计 ...

  7. poj_2195 最小费用最大流

    题目大意 一个nxm的地图,地图上的横纵交错成nxm个交叉点,其中有k个交叉点为房间,k个交叉点为k个小人的初始位置.小人可以在地图上沿着水平或垂直方向行走,每走一步的代价为1.求这k个小人分别到达k ...

  8. poj_1161 并查集

    题目大意 一个学校里面有n个学生(标号从0到n-1)和m个社团(标号从0到m-1),每个学生属于0个或多个社团.近期有SARS传播,属于同一个社团的学生的SARS可以相互传染.给出m个社团中的学生标号 ...

  9. 关于用phonegap 3.0+ 打包后sencha touch按钮点击切换动画延迟接近一秒的以及界面闪烁的解决方案

    android的webview对硬件加速的支持貌似很不理想,在开启硬件加速的情况下,css3这些需要调用硬件加速的样式会大幅拖慢html5的webapp,在htc的部分手机上还会因开启硬件加速而导致闪 ...

  10. 【BZOJ4698】Sdoi2008 Sandy的卡片 后缀数组+RMQ

    [BZOJ4698]Sdoi2008 Sandy的卡片 Description Sandy和Sue的热衷于收集干脆面中的卡片.然而,Sue收集卡片是因为卡片上漂亮的人物形象,而Sandy则是为了积攒卡 ...