liunx文件传输
liunx之scp和rsync两种
scp&rsync
** 备份方式对比**
方式 | scp | rsync |
---|---|---|
备份方式 | 全量备份 | 增量备份 |
scp
Scp在主机间复制文件。他使用 ssh(1)作为数据传输。而且用同样认证和安全性。
使用方式:scp 文件源 (局域网ip):文件目的路径
由于是局域网如下代码需要输入yes和要访问服务器的ip
参数
-r 复制目录(递归)
-p 指定端口号
[root@backup-62 ~]# scp /etc/hostname 172.16.1.21:/tmp
root@172.16.1.21's password:
hostname 100% 10 8.5KB/s 00:00
rsync
Rsync(remote synchronize)是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件
windows平台下也有相应的版本,如cwRsync和Sync2NAS等工具
源路径如果是一个目录的话,带上尾随斜线和不带尾随斜线是不一样的,不带尾随斜线表示的是整个目录包括目录本身,带上尾随斜线表示的是目录中的文件,不包括目录本身
/etc | 目录和目录的内容 |
---|---|
/etc/ | 只有目录的内容 |
参数
-a:all所有
-a --delete 把复制目录和复制目的目录保持一致
-v :显示过程
-av:av大片呀!所有的我都看着
-z : 传输的过程中压缩
-r : 递归
–exclude :排除那些不需要传递的文件
-l : 传递链接文件
-p : --prems 权限
-t : time时间不变
-g : --group
-o : --owner
模式
本地ssh模式
rsync -av
隧道模式(ssh)
- ssh +端口远程控制
ssh+端口号:可以远程操作局域网电脑
[root@backup-62 ~]# ssh -p 22 172.16.1.21
\root@172.16.1.21's password:
Last login: Thu Jan 24 22:42:50 2019 from 172.16.1.62
[root@demo-nfs-21 ~]#
- 单纯指定端口
-e :指定端口
rsync -avz -e ‘ssh -p:22’ /etc/sysconfig/ 172.16.1.41:/tmp - 端口基础上文件拉和推
利用ssh通道rsync同步,双方机器都能推拉
push: rsync -avzP -e"ssh -p22" sourecefile user@ip:directory
pull:rsync -avzP -e"ssh -p22" user@ip:directory/file directory
守护进程模式
daemon守护进程服务
服务端搭建
实时同步
sersync(inotify+rsync)
inotify监控目录下文件实时更新
sersync官网
https://github.com/wsgzao/sersync
- 配置文件路径:百度链接
链接:https://pan.baidu.com/s/15i0_NV-IZW1_BvB15DtUQg
提取码:cyu2
复制这段内容后打开百度网盘手机App,操作更方便哦 - 解压文件uzip 文件
root@nfs01 ~]# unzip sersync_installdir_64bit.zip
Archive: sersync_installdir_64bit.zip
creating: sersync_installdir_64bit/
creating: sersync_installdir_64bit/sersync/
creating: sersync_installdir_64bit/sersync/bin/
inflating: sersync_installdir_64bit/sersync/bin/sersync
creating: sersync_installdir_64bit/sersync/conf/
inflating: sersync_installdir_64bit/sersync/conf/confxml.xml
creating: sersync_installdir_64bit/sersync/logs/
[root@nfs01 ~]# mv sersync_installdir_64bit/sersync/ /usr/local/
[root@nfs01 ~]# tree /usr/local/sersync/
- 修改配置文件
[root@demo-nfs-21 ~]# tree /usr/local/sersync/
/usr/local/sersync/
├── bin
│ └── sersync
├── conf
│ └── confxml.xml#配置文件
└── logs
- 修改配置文件
inotify