全量和增量
全量就是把所有文件一股脑的全部传输过去,也不管他一不一样,比如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 = rsyncgid = rsyncfake super = yesuse chroot = nomax connections = 4pid file = /var/run/rsyncd.pidexclude = lost+found/
log file = /var/log/rsyncd.log#transfer logging = yestimeout = 900ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2auth users = rsync_backupsecrets 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