通过网络复制后,稀疏文件明显变大(但仍然稀疏)

bil*_*lyw 5 linux

当尝试通过网络将稀疏 VM 映像文件从一个 KVM 管理程序复制到另一个 KVM 管理程序时,我看到以下行为:

  • 稀疏文件仍然是稀疏文件
  • 复制的稀疏文件明显大于原始稀疏文件

来源:

[root@kvm1 thin_images]# ls -lhs
total 2.6G
1.4G -rw-------. 1 root root 8.0G Jul 20 11:10 centos6-8g.img
1.3G -rw-------. 1 root root 8.0G Jul 20 10:50 debian7-8g.img
Run Code Online (Sandbox Code Playgroud)

目的地:

[root@kvm2 thin_images]# ls -lhs
total 11G
4.8G -rw-------. 1 root root 8.0G Jul 20 11:10 centos6-8g.img
6.2G -rw-------. 1 root root 8.0G Jul 20 10:50 debian7-8g.img
Run Code Online (Sandbox Code Playgroud)

如您所见,CentOS 映像的稀疏文件现在为 4.8G,而不是 1.4G。对于 Debian 镜像,它从 1.3G 增长到 6.2G。

我尝试过通过网络复制的方法包括脏 nc-tar 管道带有 --sparse 和 --inplace 选项的 rsync。虚拟机管理程序不在足够新的 Linux 内核上使用bsdtar 的 SEEK_HOLE 功能,它们本身也没有 bsdtar 。

对这种行为有什么解释吗?通过网络复制目标稀疏文件后,目标稀疏文件是否可以保持与原始稀疏文件相同的大小?

其他信息:

[root@kvm1 thin_images]# uname -a
Linux kvm1 2.6.32-504.23.4.el6.x86_64 #1 SMP Tue Jun 9 20:57:37 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@kvm1 thin_images]# yum list installed rsync tar nc
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: centos-mirror.jchost.net
 * extras: mirror.spro.net
 * updates: mirror.es.its.nyu.edu
Installed Packages
nc.x86_64                                                  1.84-22.el6                                                 @base                                   
rsync.x86_64                                               3.0.6-12.el6                                                @anaconda-CentOS-201410241409.x86_64/6.6
tar.x86_64                                                 2:1.23-11.el6                                               @anaconda-CentOS-201410241409.x86_64/6.6
Run Code Online (Sandbox Code Playgroud)

小智 4

rsync 等通常只会在一定数量的字节之后稀疏,并且通常只会在块大小上(需要阅读源代码,但我记得一些基于块大小的内容)来决定使用稀疏方法的方式。因此,写入单个字节的块将被复制和写入,从而分配块大小,而不是仅查找该字节,然后查找其余字节。在原始文件中,块大小为 512 字节,但传输等。(为了优化)块大小约为 64k。因此,64kb 中的单个字节集会将 64kb 写入磁盘,而不是寻求稀疏该“块”。

即使在这些映像的本地文件系统上执行 rsync,您也可能会看到类似的结果。

看看这些帖子传输:https://rwmj.wordpress.com/2010/10/19/tip-making-a-disk-image-sparse/http://blog.easter-eggs.org/ index.php/post/2013/09/24/Convert-an-unsparse-vm-image-to-sparse-vm-image 您给出的链接中的建议也将适用:

  1. rsync --稀疏本地 dest://directory/
  2. 使用这些工具使其再次稀疏
  3. 在所有后续运行中使用 rsync --inplace
  4. 如果文件再次变得“太大”,则重新稀疏文件