没有合适的资源?快使用搜索试试~ 我知道了~
首页linux rsync命令使用手册
linux rsync命令使用手册
4星 · 超过85%的资源 需积分: 15 11 下载量 156 浏览量
更新于2023-03-03
评论
收藏 125KB PDF 举报
Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.
资源详情
资源评论
资源推荐
rsync(1) rsync(1)
NAME
rsync — a fast, versatile, remote (and local) file-copying tool
SYNOPSIS
Local: rsync [OPTION...] SRC... [DEST]
Access via remote shell:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST:DEST
Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
Usages with just one SRC arg and no DEST arg will list the source files instead of copying.
DESCRIPTION
Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from
another host over any remote shell, or to/from a remote rsync daemon. It offers a large number
of options that control every aspect of its behavior and permit very flexible specification of
the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the
amount of data sent over the network by sending only the differences between the source files
and the existing files in the destination. Rsync is widely used for backups and mirroring and
as an improved copy command for everyday use.
Rsync finds files that need to be transferred using a "quick check" algorithm (by default) that
looks for files that have changed in size or in last-modified time. Any changes in the other
preserved attributes (as requested by options) are made on the destination file directly when
the quick check indicates that the file’s data does not need to be updated.
Some of the additional features of rsync are:
o support for copying links, devices, owners, groups, and permissions
o exclude and exclude-from options similar to GNU tar
o a CVS exclude mode for ignoring the same files that CVS would ignore
o can use any transparent remote shell, including ssh or rsh
o does not require super-user privileges
o pipelining of file transfers to minimize latency costs
o support for anonymous or authenticated rsync daemons (ideal for mirroring)
GENERAL
Rsync copies files either to or from a remote host, or locally on the current host (it does not
support copying files between two remote hosts).
There are two different ways for rsync to contact a remote system: using a remote-shell program
as the transport (such as ssh or rsh) or contacting an rsync daemon directly via TCP. The
remote-shell transport is used whenever the source or destination path contains a single colon
(:) separator after a host specification. Contacting an rsync daemon directly happens when the
source or destination path contains a double colon (::) separator after a host specification, OR
when an rsync:// URL is specified (see also the "USING RSYNC-DAEMON FEATURES VIA A REMOTE-SHELL
CONNECTION" section for an exception to this latter rule).
As a special case, if a single source arg is specified without a destination, the files are
listed in an output format similar to "ls -l".
As expected, if neither the source or destination path specify a remote host, the copy occurs
locally (see also the --list-only option).
Rsync refers to the local side as the "client" and the remote side as the "server". Don’t con‐
fuse "server" with an rsync daemon — a daemon is always a server, but a server can be either a
daemon or a remote-shell spawned process.
SETUP
See the file README for installation instructions.
Once installed, you can use rsync to any machine that you can access via a remote shell (as well
as some that you can access using the rsync daemon-mode protocol). For remote transfers, a mod‚Äê
ern rsync uses ssh for its communications, but it may have been configured to use a different
remote shell by default, such as rsh or remsh.
You can also specify any remote shell you like, either by using the -e command line option, or
by setting the RSYNC_RSH environment variable.
Note that rsync must be installed on both the source and destination machines.
USAGE
You use rsync in the same way you use rcp. You must specify a source and a destination, one of
which may be remote.
Perhaps the best way to explain the syntax is with some examples:
rsync -t *.c foo:src/
This would transfer all files matching the pattern *.c from the current directory to the direc‚Äê
tory src on the machine foo. If any of the files already exist on the remote system then the
rsync remote-update protocol is used to update the file by sending only the differences. See the
tech report for details.
rsync -avz foo:src/bar /data/tmp
This would recursively transfer all files from the directory src/bar on the machine foo into the
/data/tmp/bar directory on the local machine. The files are transferred in "archive" mode, which
ensures that symbolic links, devices, attributes, permissions, ownerships, etc. are preserved in
the transfer. Additionally, compression will be used to reduce the size of data portions of the
transfer.
rsync -avz foo:src/bar/ /data/tmp
A trailing slash on the source changes this behavior to avoid creating an additional directory
level at the destination. You can think of a trailing / on a source as meaning "copy the con‚Äê
tents of this directory" as opposed to "copy the directory by name", but in both cases the
attributes of the containing directory are transferred to the containing directory on the desti‚Äê
nation. In other words, each of the following commands copies the files in the same way,
including their setting of the attributes of /dest/foo:
rsync -av /src/foo /dest
rsync -av /src/foo/ /dest/foo
Note also that host and module references don’t require a trailing slash to copy the contents of
the default directory. For example, both of these copy the remote directory’s contents into
"/dest":
rsync -av host: /dest
rsync -av host::module /dest
You can also use rsync in local-only mode, where both the source and destination don’t have a
’:’ in the name. In this case it behaves like an improved copy command.
Finally, you can list all the (listable) modules available from a particular rsync daemon by
leaving off the module name:
rsync somehost.mydomain.com::
See the following section for more details.
ADVANCED USAGE
The syntax for requesting multiple files from a remote host is done by specifying additional
remote-host args in the same style as the first, or with the hostname omitted. For instance,
all these work:
rsync -av host:file1 :file2 host:file{3,4} /dest/
rsync -av host::modname/file{1,2} host::modname/file3 /dest/
rsync -av host::modname/file1 ::modname/file{3,4}
Older versions of rsync required using quoted spaces in the SRC, like these examples:
rsync -av host:'dir1/file1 dir2/file2' /dest
rsync host::'modname/dir1/file1 modname/dir2/file2' /dest
This word-splitting still works (by default) in the latest rsync, but is not as easy to use as
the first method.
If you need to transfer a filename that contains whitespace, you can either specify the --pro‚Äê
tect-args (-s) option, or you’ll need to escape the whitespace in a way that the remote shell
will understand. For instance:
rsync -av host:'file\ name\ with\ spaces' /dest
CONNECTING TO AN RSYNC DAEMON
It is also possible to use rsync without a remote shell as the transport. In this case you will
directly connect to a remote rsync daemon, typically using TCP port 873. (This obviously
requires the daemon to be running on the remote system, so refer to the STARTING AN RSYNC DAEMON
TO ACCEPT CONNECTIONS section below for information on that.)
Using rsync in this way is the same as using it with a remote shell except that:
o you either use a double colon :: instead of a single colon to separate the hostname from
the path, or you use an rsync:// URL.
o the first word of the "path" is actually a module name.
o the remote daemon may print a message of the day when you connect.
o if you specify no path name on the remote daemon then the list of accessible paths on the
daemon will be shown.
o if you specify no local destination then a listing of the specified files on the remote
daemon is provided.
o you must not specify the --rsh (-e) option.
An example that copies all the files in a remote module named "src":
rsync -av host::src /dest
Some modules on the remote daemon may require authentication. If so, you will receive a password
prompt when you connect. You can avoid the password prompt by setting the environment variable
RSYNC_PASSWORD to the password you want to use or using the --password-file option. This may be
useful when scripting rsync.
WARNING: On some systems environment variables are visible to all users. On those systems using
--password-file is recommended.
You may establish the connection via a web proxy by setting the environment variable RSYNC_PROXY
to a hostname:port pair pointing to your web proxy. Note that your web proxy’s configuration
must support proxy connections to port 873.
You may also establish a daemon connection using a program as a proxy by setting the environment
variable RSYNC_CONNECT_PROG to the commands you wish to run in place of making a direct socket
connection. The string may contain the escape "%H" to represent the hostname specified in the
rsync command (so use "%%" if you need a single "%" in your string). For example:
export RSYNC_CONNECT_PROG='ssh proxyhost nc %H 873'
rsync -av targethost1::module/src/ /dest/
rsync -av rsync:://targethost2/module/src/ /dest/
The command specified above uses ssh to run nc (netcat) on a proxyhost, which forwards all data
to port 873 (the rsync daemon) on the targethost (%H).
USING RSYNC-DAEMON FEATURES VIA A REMOTE-SHELL CONNECTION
It is sometimes useful to use various features of an rsync daemon (such as named modules) with‚Äê
out actually allowing any new socket connections into a system (other than what is already
required to allow remote-shell access). Rsync supports connecting to a host using a remote
shell and then spawning a single-use "daemon" server that expects to read its config file in the
home dir of the remote user. This can be useful if you want to encrypt a daemon-style trans‚Äê
fer’s data, but since the daemon is started up fresh by the remote user, you may not be able to
use features such as chroot or change the uid used by the daemon. (For another way to encrypt a
daemon transfer, consider using ssh to tunnel a local port to a remote machine and configure a
normal rsync daemon on that remote host to only allow connections from "localhost".)
From the user’s perspective, a daemon transfer via a remote-shell connection uses nearly the
same command-line syntax as a normal rsync-daemon transfer, with the only exception being that
you must explicitly set the remote shell program on the command-line with the --rsh=COMMAND
option. (Setting the RSYNC_RSH in the environment will not turn on this functionality.) For
example:
rsync -av --rsh=ssh host::module /dest
If you need to specify a different remote-shell user, keep in mind that the user@ prefix in
front of the host is specifying the rsync-user value (for a module that requires user-based
authentication). This means that you must give the ’-l user’ option to ssh when specifying the
remote-shell, as in this example that uses the short version of the --rsh option:
rsync -av -e "ssh -l ssh-user" rsync-user@host::module /dest
The "ssh-user" will be used at the ssh level; the "rsync-user" will be used to log-in to the
"module".
STARTING AN RSYNC DAEMON TO ACCEPT CONNECTIONS
In order to connect to an rsync daemon, the remote system needs to have a daemon already running
(or it needs to have configured something like inetd to spawn an rsync daemon for incoming con‚Äê
nections on a particular port). For full information on how to start a daemon that will han‚Äê
dling incoming socket connections, see the rsyncd.conf(5) man page — that is the config file for
the daemon, and it contains the full details for how to run the daemon (including stand-alone
and inetd configurations).
If you’re using one of the remote-shell transports for the transfer, there is no need to manu‐
ally start an rsync daemon.
EXAMPLES
Here are some examples of how I use rsync.
To backup my wife’s home directory, which consists of large MS Word files and mail folders, I
use a cron job that runs
rsync -Cavz . arvidsjaur:backup
each night over a PPP connection to a duplicate directory on my machine "arvidsjaur".
To synchronize my samba source trees I use the following Makefile targets:
get:
rsync -avuzb --exclude '*~' samba:samba/ .
put:
rsync -Cavuzb . samba:samba/
sync: get put
this allows me to sync with a CVS directory at the other end of the connection. I then do CVS
operations on the remote machine, which saves a lot of time as the remote CVS protocol isn’t
very efficient.
I mirror a directory between my "old" and "new" ftp sites with the command:
rsync -az -e ssh --delete ~ftp/pub/samba nimbus:"~ftp/pub/tridge"
This is launched from cron every few hours.
OPTIONS SUMMARY
Here is a short summary of the options available in rsync. Please refer to the detailed descrip‚Äê
tion below for a complete description.
-v, --verbose increase verbosity
-q, --quiet suppress non-error messages
--no-motd suppress daemon-mode MOTD (see caveat)
-c, --checksum skip based on checksum, not mod-time & size
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
--no-OPTION turn off an implied OPTION (e.g. --no-D)
-r, --recursive recurse into directories
-R, --relative use relative path names
--no-implied-dirs don't send implied dirs with --relative
-b, --backup make backups (see --suffix & --backup-dir)
--backup-dir=DIR make backups into hierarchy based in DIR
--suffix=SUFFIX backup suffix (default ~ w/o --backup-dir)
-u, --update skip files that are newer on the receiver
--inplace update destination files in-place
--append append data onto shorter files
--append-verify --append w/old data in file checksum
-d, --dirs transfer directories without recursing
-l, --links copy symlinks as symlinks
-L, --copy-links transform symlink into referent file/dir
--copy-unsafe-links only "unsafe" symlinks are transformed
--safe-links ignore symlinks that point outside the tree
-k, --copy-dirlinks transform symlink to dir into referent dir
-K, --keep-dirlinks treat symlinked dir on receiver as dir
-H, --hard-links preserve hard links
-p, --perms preserve permissions
-E, --executability preserve executability
--chmod=CHMOD affect file and/or directory permissions
-A, --acls preserve ACLs (implies -p)
-X, --xattrs preserve extended attributes
-o, --owner preserve owner (super-user only)
-g, --group preserve group
--devices preserve device files (super-user only)
--specials preserve special files
-D same as --devices --specials
-t, --times preserve modification times
-O, --omit-dir-times omit directories from --times
--super receiver attempts super-user activities
--fake-super store/recover privileged attrs using xattrs
-S, --sparse handle sparse files efficiently
-n, --dry-run perform a trial run with no changes made
-W, --whole-file copy files whole (w/o delta-xfer algorithm)
-x, --one-file-system don't cross filesystem boundaries
-B, --block-size=SIZE force a fixed checksum block-size
-e, --rsh=COMMAND specify the remote shell to use
--rsync-path=PROGRAM specify the rsync to run on remote machine
--existing skip creating new files on receiver
--ignore-existing skip updating files that exist on receiver
--remove-source-files sender removes synchronized files (non-dir)
--del an alias for --delete-during
--delete delete extraneous files from dest dirs
--delete-before receiver deletes before transfer (default)
--delete-during receiver deletes during xfer, not before
--delete-delay find deletions during, delete after
--delete-after receiver deletes after transfer, not before
--delete-excluded also delete excluded files from dest dirs
--ignore-errors delete even if there are I/O errors
--force force deletion of dirs even if not empty
--max-delete=NUM don't delete more than NUM files
--max-size=SIZE don't transfer any file larger than SIZE
--min-size=SIZE don't transfer any file smaller than SIZE
--partial keep partially transferred files
--partial-dir=DIR put a partially transferred file into DIR
--delay-updates put all updated files into place at end
-m, --prune-empty-dirs prune empty directory chains from file-list
--numeric-ids don't map uid/gid values by user/group name
--timeout=SECONDS set I/O timeout in seconds
--contimeout=SECONDS set daemon connection timeout in seconds
-I, --ignore-times don't skip files that match size and time
--size-only skip files that match in size
--modify-window=NUM compare mod-times with reduced accuracy
-T, --temp-dir=DIR create temporary files in directory DIR
-y, --fuzzy find similar file for basis if no dest file
--compare-dest=DIR also compare received files relative to DIR
--copy-dest=DIR ... and include copies of unchanged files
--link-dest=DIR hardlink to files in DIR when unchanged
-z, --compress compress file data during the transfer
--compress-level=NUM explicitly set compression level
--skip-compress=LIST skip compressing files with suffix in LIST
-C, --cvs-exclude auto-ignore files in the same way CVS does
-f, --filter=RULE add a file-filtering RULE
-F same as --filter='dir-merge /.rsync-filter'
repeated: --filter='- .rsync-filter'
--exclude=PATTERN exclude files matching PATTERN
--exclude-from=FILE read exclude patterns from FILE
--include=PATTERN don't exclude files matching PATTERN
--include-from=FILE read include patterns from FILE
--files-from=FILE read list of source-file names from FILE
-0, --from0 all *from/filter files are delimited by 0s
-s, --protect-args no space-splitting; wildcard chars only
--address=ADDRESS bind address for outgoing socket to daemon
--port=PORT specify double-colon alternate port number
--sockopts=OPTIONS specify custom TCP options
--blocking-io use blocking I/O for the remote shell
--stats give some file-transfer stats
-8, --8-bit-output leave high-bit chars unescaped in output
-h, --human-readable output numbers in a human-readable format
--progress show progress during transfer
-P same as --partial --progress
-i, --itemize-changes output a change-summary for all updates
--out-format=FORMAT output updates using the specified FORMAT
--log-file=FILE log what we're doing to the specified FILE
--log-file-format=FMT log updates using the specified FMT
--password-file=FILE read daemon-access password from FILE
--list-only list the files instead of copying them
--bwlimit=KBPS limit I/O bandwidth; KBytes per second
--write-batch=FILE write a batched update to FILE
--only-write-batch=FILE like --write-batch but w/o updating dest
--read-batch=FILE read a batched update from FILE
--protocol=NUM force an older protocol version to be used
--iconv=CONVERT_SPEC request charset conversion of filenames
--checksum-seed=NUM set block/file checksum seed (advanced)
-4, --ipv4 prefer IPv4
-6, --ipv6 prefer IPv6
--version print version number
(-h) --help show this help (see below for -h comment)
Rsync can also be run as a daemon, in which case the following options are accepted:
--daemon run as an rsync daemon
--address=ADDRESS bind to the specified address
--bwlimit=KBPS limit I/O bandwidth; KBytes per second
--config=FILE specify alternate rsyncd.conf file
--no-detach do not detach from the parent
--port=PORT listen on alternate port number
--log-file=FILE override the "log file" setting
--log-file-format=FMT override the "log format" setting
--sockopts=OPTIONS specify custom TCP options
-v, --verbose increase verbosity
-4, --ipv4 prefer IPv4
-6, --ipv6 prefer IPv6
-h, --help show this help (if used after --daemon)
OPTIONS
rsync uses the GNU long options package. Many of the command line options have two variants, one
short and one long. These are shown below, separated by commas. Some options only have a long
variant. The ’=’ for options that take a parameter is optional; whitespace can be used instead.
--help Print a short help page describing the options available in rsync and exit. For back‚Äê
ward-compatibility with older versions of rsync, the help will also be output if you use
the -h option without any other args.
--version
print the rsync version number and exit.
-v, --verbose
This option increases the amount of information you are given during the transfer. By
default, rsync works silently. A single -v will give you information about what files are
being transferred and a brief summary at the end. Two -v options will give you informa‚Äê
tion on what files are being skipped and slightly more information at the end. More than
two -v options should only be used if you are debugging rsync.
Note that the names of the transferred files that are output are done using a default
--out-format of "%n%L", which tells you just the name of the file and, if the item is a
link, where it points. At the single -v level of verbosity, this does not mention when a
file gets its attributes changed. If you ask for an itemized list of changed attributes
(either --itemize-changes or adding "%i" to the --out-format setting), the output (on the
client) increases to mention all items that are changed in any way. See the --out-format
option for more details.
-q, --quiet
This option decreases the amount of information you are given during the transfer,
notably suppressing information messages from the remote server. This option is useful
when invoking rsync from cron.
--no-motd
This option affects the information that is output by the client at the start of a daemon
transfer. This suppresses the message-of-the-day (MOTD) text, but it also affects the
剩余29页未读,继续阅读
xz
- 粉丝: 12
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- 2022年中国足球球迷营销价值报告.pdf
- 房地产培训 -营销总每天在干嘛.pptx
- 黄色简约实用介绍_汇报PPT模板.pptx
- 嵌入式系统原理及应用:第三章 ARM编程简介_3.pdf
- 多媒体应用系统.pptx
- 黄灰配色简约设计精美大气商务汇报PPT模板.pptx
- 用matlab绘制差分方程Z变换-反变换-zplane-residuez-tf2zp-zp2tf-tf2sos-sos2tf-幅相频谱等等.docx
- 网络营销策略-网络营销团队的建立.docx
- 电子商务示范企业申请报告.doc
- 淡雅灰低面风背景完整框架创业商业计划书PPT模板.pptx
- 计算模型与算法技术:10-Iterative Improvement.ppt
- 计算模型与算法技术:9-Greedy Technique.ppt
- 计算模型与算法技术:6-Transform-and-Conquer.ppt
- 云服务安全风险分析研究.pdf
- 软件工程笔记(完整版).doc
- 电子商务网项目实例规划书.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1