scp和rsync

全量和增量

全量就是把所有文件一股脑的全部传输过去,也不管他一不一样,比如scp
增量就是在传输前先对比一下两边的文件一不一样,有一样的部分,哪一样的部分就不传输,只传输不一样的部分,和新增的部分   ,比如rsync

scp 传输

语法: scp  本机路径  用户@ip:/路径‘
-r 传输目录
-p 保持属性不变

rsync

rsync  -av /etc/  用户@ip:/路径‘
这个是推
rsync  -av /etc/  root@192.168.103.25:/etc/
这个是拉
rsync  -av root@192.168.103.25:/etc/ /etc/  


/etc  和  /etc/ 的区别
/etc  表示传输目录下面的内容,包含目录本身
/etc/ 传输目录下面的内容,不包含目录本身

rysnc 服务端和客户端

192.168.23.103 test3服务端
192.168.23.102 test2客户端

rysnc 服务端操作

yum  install rsync -y

#看一下这个配置文件,我们要根据这个配置文件在服务端上一一创建
[root@test3 ~]# cat /etc/rsyncd.conf 
 #/etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

 uid = rsync
 gid = rsync
 fake super = yes
 use chroot = no
 max connections = 4
 pid file = /var/run/rsyncd.pid
 exclude = lost+found/
log file = /var/log/rsyncd.log
 #transfer logging = yes
 timeout = 900
 ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
 auth users = rsync_backup
 secrets file = /etc/rsync.password
[data]
comment = www by oldboy 14:08
path = /data 
read only = no
list = yes
# [ftp]
#        path = /home/ftp
#        comment = ftp export area


[root@test3 ~]# useradd -s /sbin/nologin -M rsync
 -M, --no-create-home          do not create the user's home directory

创建密码,格式 用户名:密码
[root@test3 ~]# echo 'rsync_bakeup:1' > /etc/rsync.password
[root@test3 ~]# chmod 600 /etc/rsync.password 

1后面有个空格
[root@test3 ~]# cat -A /etc/rsync.password 
rsync_bakeup:1$
创建目录
[root@test3 ~]# mkdir /data
[root@test3 ~]# chown rsync.rsync /data/

[root@test3 ~]# systemctl restart rsyncd

[root@test3 ~]# ps -ef|grep rsync
root       6752      1  0 22:41 ?        00:00:00 /usr/bin/rsync --daemon --no-detach
root       6756   6636  0 22:43 pts/0    00:00:00 grep --color=auto rsync
[root@test3 ~]# netstat -tunlp|grep rsync
tcp        0      0 0.0.0.0:873             0.0.0.0:*               LISTEN      6752/rsync          
tcp6       0      0 :::873                  :::*                    LISTEN      6752/rsync   



[root@test3 ~]# chown rsync.rsync /xp/ -R
[root@test3 ~]# 
[root@test3 ~]# 
[root@test3 ~]# rsync -av /xp/  rsync_backup@192.168.23.103::data
Password: 
sending incremental file list
./
1
xp2/
xp2/xp/

sent 187 bytes  received 58 bytes  163.33 bytes/sec
total size is 0  speedup is 0.00

客户端测试也是一样的命令,前提是得该属组属主
[root@test2 ~]# rsync -av /xp/  rsync_backup@192.168.23.103::data

创建客户端密码文件

echo 1 > /etc/rsync.client
[root@test2 ~]# mkdir /xp
[root@test2 ~]# echo 1 > /xp/2
[root@test2 ~]# chown rsync.rsync /xp/2 
[root@test2 ~]# useradd rsync -s /sbin/nologin -M 

[root@test2 ~]#  rsync -av /xp/2  rsync_backup@192.168.23.103::data --password-file=/etc/rsync.client 
sending incremental file list
2
rsync: chgrp ".2.zUzfTv" (in data) failed: Operation not permitted (1)

sent 92 bytes  received 118 bytes  420.00 bytes/sec
total size is 2  speedup is 0.01
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179) [sender=3.1.2]

进行md5 值校验

[root@test3 ~]# find /data/ -type f|xargs md5sum
d41d8cd98f00b204e9800998ecf8427e  /data/1
126a8a51b9d1bbd07fddc65819a542c3  /data/hostname
b026324c6904b2a9cb4b88d6d61c81d1  /data/2

[root@test3 ~]# find /data/ -type f |xargs md5sum > 1
[root@test3 ~]# 
[root@test3 ~]# 
[root@test3 ~]# md5sum --check 1
/data/1: OK
/data/hostname: OK
/data/2: OK

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值