linux - rsync 和 --link-dest 的磁盘使用问题

标签 linux bash shell backup rsync

我在使用 rsync--link-dest 时遇到磁盘使用问题 增量备份正在占用整个磁盘空间:

@localhost media]$ ls
orig
----------------------------------------------------
localhost media]$ du -sh .
25M .
----------------------------------------------------
localhost media]$ rsync -avh orig/ full
----------------------------------------------------
@localhost media]$ du -sh .
49M .
----------------------------------------------------
localhost media]$ echo 1111 > orig/foo111
----------------------------------------------------
localhost media]$ rsync -avh --link-dest=full orig/ orig_1
----------------------------------------------------
localhost media]$ ls orig_1/foo111 
orig_1/foo111
_____________________________________________________

localhost media]$ ls full/foo111
ls: cannot access full/foo111: No such file or directory

到目前为止一切看起来都很好。最新的变化反射(reflect)在 orig_1 但是这些目录不是硬链接(hard link)的,它们都是完整大小的。

-----------------------------------------------------
localhost media]$ du -sh .
74M .
---------------------------------------------
localhost media]$ du -sh orig_1/
25M orig_1/
--------------------------------------------
localhost media]$ du -sh orig
25M orig
---------------------------------------------
localhost media]$ du -sh full
25M full

我应该将 orig_1 大小设置为 0 吗? stat 命令显示没有硬链接(hard link)。我做错了什么?

最佳答案

当您运行 rsync -avh --link-dest=full orig/orig_1 时,您忽略了此错误消息(如果删除 -v 则更明显):

--link-dest arg does not exist: full

如果我们接着查看 --link-dest 下的 man rsync,我们会发现:

If DIR is a relative path, it is relative to the destination directory. 

就是这样。 full 是相对于当前目录的。相对于目标目录,它将是 ../full

如果您使用 rsync -avh --link-dest=../full orig/orig_1 再次尝试,您会得到预期的结果:

$ du -sh *
149M    full
149M    orig
232K    orig_1
$ du -sh .
298M    .

请注意,当单独计算时,目录仍会占用全部空间:

$ du -sh orig_1 
149M    orig_1

这是因为 du 会跟踪它已经看到的文件,并避免将它们计数两次。

关于linux - rsync 和 --link-dest 的磁盘使用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21298179/

相关文章:

php - 如何设置文档根目录以使用 Nginx 加载 Laravel 应用程序?

linux - 我应该选择哪种 Linux RTOS 解决方案?

json - 输出分号分隔的字符串

linux - 如何一次重命名多个文件

android - 为什么 fork 炸弹没有让 android 崩溃?

c - 如何在 MinGW 中使用预编译静态库?

windows - 如何在 git bash 中注册新安装的驱动器?

bash - 在 MongoDB 查询中使用 shell 变量

regex - 将 cmd 输出的正则表达式结果返回到变量

linux - Tesseract 批量将图像转换为可搜索的 PDF 和多个相应的文本文件