系统间复制文档

系统间复制文档

windows和linux之间传输

  • xftp工具

  • xshell

Linux服务器安装 lrzsz 软件包。该方式传输速度比ftp慢。

上传:直接将文件拖拽到命令行窗口即可。或者使用 rz 工具,并指定上传文件。

拉取:使用 sz 工具,并指定保存位置。

Linux 之间传输

scp 命令

scp,全名secure copy,也就是安全复制,是基于ssh协议,也就是说Linux服务器要开启ssh服务。

[root@client ~ 16:36:13]# scp root@server:/root/etc-250729.tar .
root@server's password: 
etc-250729.tar                                                              100%   37MB  93.8MB/s   00:00    
[root@client ~ 16:39:14]# ls etc*
etc-250729.tar
#复制多个文件
[root@client ~ 16:39:24]# scp root@server:/root/{etc-250729.tar,etc.tar} .
root@server's password: 
etc-250729.tar                                                              100%   37MB 132.8MB/s   00:00    
#复制目录,使用-r选项
[root@client ~ 17:15:02]# scp root@server:/etc/selinux/ .
root@server's password: 
scp: /etc/selinux: not a regular file
[root@client ~ 17:20:19]# scp -r root@server:/etc/selinux/ .
root@server's password: 
semanage.conf                                                               100% 2321     1.3MB/s   00:00    
config                                                                      100%  543   202.6KB/s   00:00    
semanage.read.LOCK                                                          100%    0     0.0KB/s   00:00    
semanage.trans.LOCK                                                         100%    0     0.0KB/s   00:00    
README.migrated                                                             100%  282   125.0KB/s   00:00    
.policy.sha512                                                              100%  129   142.8KB/s   00:0


# 上传,如果路径没有写,表示相对用户家目录。这里是上传到root用户家目录/root

scp 命令缺点:不管目的位置是否有文件,总是再复制一次,可以理解为全量备份。缺少比对功能。

rsync 命令

Rsync(Remote Synchronize)是一款开源的、快速的、多功能的、远程数据同步备份工具,并且支持多种操作系统平台运行。

Rsync具有本地与远程两台主机之间的数据快速复制同步镜像、远程备份等功能,该功能类似scp,但是优于scp功能,还具有本地不同分区目录之间全量及增量复制数据。

Rsync同步数据镜像时,通过“quick check”算法,仅同步大小或最后修改时间发生变化的文件或目录,当然也可以根据权限,属主等属性变化的同步,所以可以实现快速同步。

前提:客户端和服务端都要提前安装好 rsync 软件包。

shell 模式

shell 模式是基于 ssh 服务传送。

[root@client ~ 17:00:44]# mkdir pictures
[root@client ~ 17:01:00]# touch pictures/sanp{1..5}.jpg
[root@client ~ 17:01:19]# rsync -av pictures root@server:
root@server's password: 
sending incremental file list
pictures/
pictures/sanp1.jpg
pictures/sanp2.jpg
pictures/sanp3.jpg
pictures/sanp4.jpg
pictures/sanp5.jpg

sent 351 bytes  received 115 bytes  133.14 bytes/sec
total size is 0  speedup is 0.00


#再次同步
[root@client ~ 17:01:59]# rsync -av pictures root@server:
root@server's password: 
sending incremental file list

sent 149 bytes  received 17 bytes  66.40 bytes/sec
total size is 0  speedup is 0.00

#更新时间戳
[root@client ~ 17:03:37]# touch pictures/snap{1,2}*
[root@client ~ 17:04:22]# rsync -av pictures root@server:
root@server's password: 
sending incremental file list
pictures/
pictures/snap1*
pictures/snap2*

sent 273 bytes  received 58 bytes  132.40 bytes/sec
total size is 0  speedup is 0.00

#删除SRC中文件,默认不会同步删除DEST中文件
[root@client ~ 17:04:27]# rm -f pictures/snap5.jpg
[root@client ~ 17:06:21]# rsync -av pictures root@server:
root@server's password: 
sending incremental file list

sent 188 bytes  received 17 bytes  82.00 bytes/sec
total size is 0  speedup is 0.00

#使用选项——delete同步删除DEST中文件
[root@client ~ 17:14:13]# rm -f pictures/sanp5.jpg
[root@client ~ 17:14:38]# ls pictures/*
pictures/sanp1.jpg  pictures/sanp3.jpg  pictures/snap1*
pictures/sanp2.jpg  pictures/sanp4.jpg  pictures/snap2*
[root@client ~ 17:14:43]# rsync -av pictures root@server: 
root@server's password: 
sending incremental file list
pictures/

sent 174 bytes  received 20 bytes  77.60 bytes/sec
total size is 0  speedup is 0.00
[root@client ~ 17:14:52]# rsync -av pictures root@server: --delete
root@server's password: 
sending incremental file list

常用选项

  • -n 参数执行一次空运行,与真实执行显示结果一致,但是没有做任何改变。
  • -v 显示执行过程中详细输出。
  • -a 代表“archive mode”,会启用参数:-r -l -p -t -g -o -D
  • -r 递归同步整个文件夹
  • -l 同步软连接
  • -p 保留权限
  • -t 保留时间戳
  • -g 保留所属组
  • -o 保留所有者
  • -D 同步设备文件

说明:

  • -A,同步时保留ACLs内容。
  • -X 同步时保留selinux内容。-a,不同步acl selinux内容。

将目标文件拉取到本地,操作过程一致。

同步注意事项:

  • 文件访问时间等属性、读写等权限、文件内容等有任何变动,都会被认为修改。
  • 目标目录下如果文件比源目录还新,则不会同步。
  • 源路径的最后是否有斜杠有不同的含义:
    • 有斜杠,只是复制目录中的文件。
    • 没有斜杠的话,不但要复制目录中的文件,还要复制目录本身
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值