rsync

rsync

rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步。

rsync支持很多特性:

  • 可以镜像保存整个目录树和文件系统
  • 可以很容易做到保持原来文件的权限、时间、软硬链接等等
  • 无须特殊权限即可安装
  • 快速:第一次同步时rsync会复制全部内容,但在下一次只传输修改过的文件。rsync在传输数据的过程中可以实行压缩及解压缩操作,因此可以使用更少的带宽
  • 安全:可以使用scp、ssh等方式来传输文件,当然也可以通过直接的socket连接
  • 支持匿名传输,以方便进行网站镜像

rsync命令来同步系统文件之前要先登录remote主机认证,认证过程中用到的协议有2种:

  • ssh协议
  • rsync协议

rsync server端不用启动rsync的daemon进程,只要获取remote host的用户名和密码就可以直接rsync同步文件
rsync server端因为不用启动daemon进程,所以也不用配置文件/etc/rsyncd.conf

ssh认证协议跟scp的原理是一样的,如果在同步过程中不想输入密码就用ssh-keygen -t rsa打通通道

//这种方式默认是省略了 -e ssh 的,与下面等价:
rsync -avz /SRC -e ssh root@172.16.12.129:/DEST
-a //文件宿主变化,时间戳不变
-z //压缩数据传输

//当遇到要修改端口的时候,我们可以:
rsync -avz /SRC -e “ssh -p2222” root@172.16.12.129:/DEST
//修改了ssh 协议的端口,默认是22

//Rsync的命令格式常用的有以下三种:
rsync [OPTION]… SRC DEST
rsync [OPTION]… SRC [USER@]HOST:DEST
rsync [OPTION]… [USER@]HOST:SRC DEST

`bash
源主机
[root@mr ~]# dnf -y install rsync
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 2:52:42 ago on Thu Sep 22 15:33:54 2022.

Package rsync-3.1.3-12.el8.x86_64 is already installed.

Dependencies resolved.

Nothing to do.

Complete!

目标主机
[root@localhost ~]# rpm -qa | grep rsync
[root@localhost ~]#

源主机
[root@mr ~]# ls
hehe
[root@mr ~]# rsync -a hehe haha
[root@mr ~]# ls
hehe haha
因为目标主机没有安装rsync,才会导致报错
[root@mr ~]# rsync -a haha root@192.168.29.138:/tmp/
The authenticity of host ‘192.168.29.138 (192.168.29.138)’ can’t be established.

ECDSA key fingerprint is SHA256:tdaE+LT4DQfPum+TPtyff/6nFxOqf7KPuDiVS5JRc3s.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added ‘192.168.29.138’ (ECDSA) to the list of known hosts.

root@192.168.29.138’s password:
bash: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.3]
[root@mr ~]#
目标主机
[root@localhost ~]# ls /tmp/
systemd-private-9ec1545e3eef4502a46b97aa8affc4a5-httpd.service-Icu1Bi
systemd-private-9ec1545e3eef4502a46b97aa8affc4a5-mariadb.service-bDsu3S
systemd-private-9ec1545e3eef4502a46b97aa8affc4a5-php-fpm.service-h1dlnX
vmware-root_901-3988228452
[root@localhost ~]# dnf -y install rsync
Failed to set locale, defaulting to C.UTF-8
Repository extras is listed more than once in the configuration
Last metadata expiration check: 0:37:46 ago on Thu Sep 22 17:57:43 2022.

Dependencies resolved.

========================================================================================
Package Architecture Version Repository Size
========================================================================================
Installing:
rsync x86_64 3.1.3-19.el8 baseos 410 k

Transaction Summary

Install 1 Package

Total download size: 410 k
Installed size: 825 k
Downloading Packages:
rsync-3.1.3-19.el8.x86_64.rpm 116 kB/s | 410 kB 00:03

Original: https://www.cnblogs.com/marymary/p/16721238.html
Author: 溜溜威
Title: rsync

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/581511/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球