#简介 rsync是一种强大的命令行工具,用于在本地或远程计算机之间进行文件同步。它可以将文件从一个位置复制到另一个位置,同时节约带宽和存储空间。
这个命令在之前就已经已经接触过,同类型工具还有scp
。
这两个工具通常用来远程传输文件,但实际上用传输文件
来形容并不恰当。应该是复制文件,是将本地文件复制到远程主机,或者将远程主机文件复制到本地。同时,也可以在同一主机上复制文件,类似于cp
命令。
##rsync与scp差异
- 传输效率:rsync 可以复制已经存在于目标主机上的文件,同时只传输修改的部分。这可以显著提高传输速度,特别是在传输大文件或大型文件夹时。而 scp 则需要将整个文件/文件夹再次复制到目标主机。
- 远程传输:scp 只能在本地主机和远程主机之间传输文件,而 rsync 可以复制从一个远程主机到另一个(或者与本地主机组合)。
- 数据保护:由于 rsync 在传输数据时进行了一些冗错检查,因此更可靠。如果您的文件损坏了,传输过程中的 rsync 操作将确保自动重新上传,并验证已完成的数据。scp 在传输过程中没有提供相同的保护。
- 使用方式:rsync 当前托管在大多数操作系统存储库中,是默认预先安装的。另外,rsync 的使用方式也比 scp 更为灵活,可以设定选项来指定传输需求,并在传输结束后提供详细报告。而 scp 是基于ssh协议的安全拷贝,需要保证两端都正确安装且配置ssh,并且运行时只能接受有限的命令行选项。
#详解rsync 使用rsync -h
查看使用文档:
┌──(root㉿kali)-[~]
└─# rsync -h
rsync version 3.2.4 protocol version 31
Copyright (C) 1996-2022 by Andrew Tridgell, Wayne Davison, and others.
Web site: https://rsync.samba.org/
Capabilities:
64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
socketpairs, symlinks, symtimes, hardlinks, hardlink-specials,
hardlink-symlinks, IPv6, atimes, batchfiles, inplace, append, ACLs,
xattrs, optional protect-args, iconv, prealloc, stop-at, no crtimes
Optimizations:
SIMD-roll, no asm-roll, openssl-crypto, no asm-MD5
Checksum list:
xxh128 xxh3 xxh64 (xxhash) md5 md4 none
Compress list:
zstd lz4 zlibx zlib none
rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. See the GNU
General Public Licence for details.
rsync is a file transfer program capable of efficient remote update
via a fast differencing algorithm.
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.
Options
--verbose, -v increase verbosity
--info=FLAGS fine-grained informational verbosity
--debug=FLAGS fine-grained debug verbosity
--stderr=e|a|c change stderr output mode (default: errors)
--quiet, -q suppress non-error messages
--no-motd suppress daemon-mode MOTD
--checksum, -c