• 重要通知:网站内容不做更新,只对现有的进行扩展,新技术资料已转移到其它位置存储。

  • 通知:2021年3月21日将博客服务器迁移,感谢好友老刘提供的服务器!!!
    点击查看具体站点更新信息

  • 提示:站点启用不定时清理注册未登录的帐户,已登录过用户请无视!

  • 通知:2019年5月18日网站迎来一波大更新!!!

    点击查看具体站点更新信息

一、rsync命令本地远程守护进程方式同步备份

应用扩展 盛行 6年前 (2016-05-24) 1142次浏览 已收录 0个评论 扫描二维码
文章目录
[隐藏]

1.释义

rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了remote sync。它的特性如下:
1、可以镜像保存整个目录树和文件系统。
2、可以很容易做到保持原来文件的权限、时间、软硬链接等等。
3、无须特殊权限即可安装。
4、优化的流程,文件传输效率高。
5、可以使用rcpssh等方式来传输文件,当然也可以通过直接的socket连接。
6、支持匿名传输。

2.系统帮助

rsync  version 3.1.2  protocol version 31
Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, symtimes, prealloc

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
 -v, --verbose               详细模式输出,打印速率,文件数量等
     --info=FLAGS            fine-grained informational verbosity
     --debug=FLAGS           fine-grained debug verbosity
     --msgs2stderr           special output handling for debugging
 -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               归档模式传输,等于-tropgDl
     --no-OPTION             turn off an implied OPTION (e.g. --no-D)
 -r, --recursive             递归传输目录及子目录
 -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         set backup suffix (default ~ w/o --backup-dir)
 -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
 -d, --dirs                  transfer directories without recursing
 -l, --links                 保留软链接
 -L, --copy-links            保留软链接指向的目标文件
     --copy-unsafe-links     only "unsafe" symlinks are transformed
     --safe-links            ignore symlinks that point outside the source tree
     --munge-links           munge symlinks to make them safer (but unusable)
 -k, --copy-dirlinks         transform symlink to a dir into referent dir
 -K, --keep-dirlinks         treat symlinked dir on receiver as dir
 -H, --hard-links            preserve hard links
 -p, --perms                 保持文件权限
 -E, --executability         preserve the file's executability
     --chmod=CHMOD           affect file and/or directory permissions
 -A, --acls                  preserve ACLs (implies --perms)
 -X, --xattrs                preserve extended attributes
 -o, --owner                 保持文件属主信息
 -g, --group                 保持文件属组信息
     --devices               preserve device files (super-user only)
     --copy-devices          copy device contents as regular file
     --specials              preserve special files
 -D                          保持设备文件信息
 -t, --times                 保持文件时间信息
 -O, --omit-dir-times        omit directories from --times
 -J, --omit-link-times       omit symlinks from --times
     --super                 receiver attempts super-user activities
     --fake-super            store/recover privileged attrs using xattrs
 -S, --sparse                handle sparse files efficiently
     --preallocate           allocate dest files before writing them
 -n, --dry-run               perform a trial run with no changes made
 -W, --whole-file            copy files whole (without 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           使用的信道协议,指定替代rsh的shell程序
     --rsync-path=PROGRAM    specify the rsync to run on the remote machine
     --existing              skip creating new files on receiver
     --ignore-existing       skip updating files that already exist on receiver
     --remove-source-files   sender removes synchronized files (non-dirs)
     --del                   an alias for --delete-during
     --delete                让目标目录和源目录数据保持一致
     --delete-before         receiver deletes before transfer, not during
     --delete-during         receiver deletes during the transfer
     --delete-delay          find deletions during, delete after
     --delete-after          receiver deletes after transfer, not during
     --delete-excluded       also delete excluded files from destination dirs
     --ignore-missing-args   ignore missing source args without error
     --delete-missing-args   delete missing source args from destination
     --ignore-errors         delete even if there are I/O errors
     --force                 force deletion of directories 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               断点续传
     --partial-dir=DIR       put a partially transferred file into DIR
     --delay-updates         put all updated files into place at transfer's end
 -m, --prune-empty-dirs      prune empty directory chains from the file-list
     --numeric-ids           don't map uid/gid values by user/group name
     --usermap=STRING        custom username mapping
     --groupmap=STRING       custom groupname mapping
     --chown=USER:GROUP      simple username/groupname mapping
     --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 in size and mod-time
 -M, --remote-option=OPTION  send OPTION to the remote side only
     --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 destination 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-level=NUM    explicitly set compression level
     --skip-compress=LIST    skip compressing files with a suffix in LIST
 -C, --cvs-exclude           auto-ignore files 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-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; only wildcard special-chars
     --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                          显示同步的过程及传输时的进度信息
 -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=RATE          限速传输
     --outbuf=N|L|B          set output buffering to None, Line, or Block
     --write-batch=FILE      write a batched update to FILE
     --only-write-batch=FILE like --write-batch but w/o updating destination
     --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 (-h is --help only if used alone)

Use "rsync --daemon --help" to see the daemon-mode command-line options.
Please see the rsync(1) and rsyncd.conf(5) man pages for full documentation.
See http://rsync.samba.org/ for updates, bug reports, and answers

3.本地方式

3.1.文件增量同步

[root@itbkz.com ~]#rsync -avz /etc/passwd /client/
sending incremental file list
passwd

sent 447 bytes  received 35 bytes  964.00 bytes/sec
total size is 846  speedup is 1.76
[root@itbkz.com ~]#ll /client/
总用量 4
-rw-r--r-- 1 root root 846 12月  1 23:56 passwd

3.2.目录增量同步

3.2.1.同步目录下文件

[root@itbkz.com ~]#rsync -avz /client/ /server/
sending incremental file list
./
passwd

sent 469 bytes  received 38 bytes  1,014.00 bytes/sec
total size is 846  speedup is 1.67
[root@itbkz.com ~]#ll /server/
总用量 4
-rw-r--r-- 1 root root 846 12月  1 23:56 passwd

3.2.2.完全一致同步

[root@itbkz.com ~]#rsync -avz /client/ /server/ --delete
sending incremental file list
deleting client/passwd
deleting client/
./

sent 67 bytes  received 43 bytes  220.00 bytes/sec
total size is 846  speedup is 7.69
[root@itbkz.com ~]#ll /server/
总用量 4
-rw-r--r-- 1 root root 846 12月  1 23:56 passwd
类似于cp命令,如果要同步目录下所有的内容,目录后面必须要加“/”;如果要同步目录及目录下所有的内容,目录后面不需要加“/”;如果需要将源和目标内容完全一样,需要加“--delete

4.远程方式

4.1.本地文件到远程

[root@itbkz.com ~]#rsync -avz /server/passwd root@192.168.1.247:/client/
root@192.168.1.247's password: 
sending incremental file list
created directory /client
passwd

sent 447 bytes  received 65 bytes  93.09 bytes/sec
total size is 846  speedup is 1.65
#切换主机查看
[root@xuexi1_c76_001_247 ~]# ll /client/
总用量 4
-rw-r--r-- 1 root root 846 12月  1 23:56 passwd
如果提示“bash: rsync: 未找到命令”需要在192.168.1.247这台主机上安装rsync即可

3.2.目录增量同步

4.2.1.本地目录到远程

[root@itbkz.com ~]#rsync -avz /server/ root@192.168.1.247:/server/
root@192.168.1.247's password:
sending incremental file list
created directory /server
./
passwd

sent 469 bytes received 68 bytes 153.43 bytes/sec
total size is 846 speedup is 1.58

#切换主机查看
[root@xuexi1_c76_001_247 ~]# ll /server/
总用量 4
-rw-r--r-- 1 root root 846 12月 1 23:56 passwd

4.2.2.远程目录到本地

[root@itbkz.com ~]#rsync -avz root@192.168.1.247:/server/ /local/
root@192.168.1.247's password: 
receiving incremental file list
created directory /local
./
passwd

sent 46 bytes  received 469 bytes  147.14 bytes/sec
total size is 846  speedup is 1.64
[root@itbkz.com ~]#ll /local/
总用量 4
-rw-r--r-- 1 root root 846 12月  1 23:56 passwd

3.2.2.完全一致同步

[root@itbkz.com ~]#ll /server/
总用量 4
-rw-r--r-- 1 root root 846 12月  1 23:56 passwd
-rw-r--r-- 1 root root   0 5月  24 15:46 test.txt
[root@itbkz.com ~]#rsync -avz /server/ root@192.168.1.247:/server/ --delete
root@192.168.1.247's password: 
sending incremental file list
deleting 247.txt
./
local.txt

sent 136 bytes  received 49 bytes  52.86 bytes/sec
total size is 846  speedup is 4.57
类型于scp命令,使用ssh通道传输数据。警告:如果要清空远程目录下文件,可以将一个空的目录传到远程服务器,注意加上“--delete

5.守护进程方式

Rsync自身非常重要的功能,不使用系统用户,更加安全,参考下文

二、Rsync守护进程方式的使用方法

文章目录[隐藏] 1简介2相关3步骤3.1Rsync-Server配置3.1.1安装rsync3.1.2创建r […]


IT博客站版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:一、rsync命令本地远程守护进程方式同步备份
喜欢 (0)
[使用支付宝扫码]
分享 (0)
盛行
关于作者:
企业应用技术爱好者,喜欢分享知识。如果文章中有错误,欢迎指正,谢谢。
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址