而不增加存储空间

而不增加存储空间

本文介绍了如何按原样复制具有数据的overlayfs目录结构的/var/lib/docker,而不增加存储空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个docker安装,其中包含多个图像和/var/lib/docker中的约150Gigs数据.此设置使用overlayfs作为其存储驱动程序. /var/lib/docker/overlay下的每一层都有几个目录,其中包含实际数据.分区大小为160G.

I have a docker installation with several images and about 150Gigs of data in /var/lib/docker. This setup uses overlayfs as its storage driver. There are several directories for each layer under /var/lib/docker/overlay holding the actual data. The partition size is 160G.

我的要求是将docker目录从/var/lib/docker复制到1TB的新磁盘上,以便我将docker指向从该新分区开始并继续使用我的旧映像.

My requirement is to copy the the docker directory from /var/lib/docker to a new disk of 1TB, so that I point docker to start from this new partition and continue to use my old images.

现在的问题是,当我将rsynccp命令与-a一起使用时,将/var/lib/docker复制到新分区,而不是总共150G的实际数据,复制的总数据即将到来最高可达600G(还在增加).

Now the problem is, when I use an rsync or a cp command with -a, to copy /var/lib/docker to new partition, instead of a total of 150G actual data, the total copied data is coming to as much as 600G (and counting..).

Docker也已停止,但不确定操作系统如何查看160G数据并将其复制到600G +.我希望它不是overlayfs(合并目录). df -aTh上没有覆盖信息.它也没有帮助使用rmmod overlay

Docker is stopped as well, but not sure how OS is looking at the 160G data and copying into 600G+. I hope it is not the overlayfs (merged directories). There is no overlay information on df -aTh. Nor did it help unloading kernel overlayfs driver with rmmod overlay

我怎么可能只按原样复制此数据,而没有进行任何扩展/合并?

How is it possible that I could just copy this data as-is, without any expansion/merge taking place.

推荐答案

事实证明,docker在/var/lib/docker/overlay下这些目录中使用hardlinks.使用-H进行rsync(将硬链接复制为硬链接)即可解决此问题.

It turned out that docker is using hardlinks within those directories under /var/lib/docker/overlay. Using -H to rsync (copy hardlinks as hardlinks) solved the issue.

rsync -avPHSX /var/lib/docker /new/partition/

这篇关于如何按原样复制具有数据的overlayfs目录结构的/var/lib/docker,而不增加存储空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 15:48