bash rsync 和 --link-dest 的磁盘使用问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21298179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
disk usage issue with rsync and --link-dest
提问by user3059831
I have disk usage problem with rsync
and --link-dest
Incremental backup is taking full disk space:
我有磁盘使用问题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
Everything looks good so far. The latest change is reflected in orig_1
But the directories aren't hard linked and they're all in full size.
到目前为止,一切看起来都很好。最新的更改反映在orig_1
但目录不是硬链接的,它们都是完整大小。
-----------------------------------------------------
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
Am I suppose to have the orig_1
size as 0? And stat
command shows no hard links. What am I doing wrong?
我应该将orig_1
大小设为 0 吗?并且stat
命令显示没有硬链接。我究竟做错了什么?
回答by that other guy
When you ran rsync -avh --link-dest=full orig/ orig_1
, you ignored this error message (it's more obvious if you remove -v
):
当你运行时rsync -avh --link-dest=full orig/ orig_1
,你忽略了这个错误信息(如果你删除它会更明显-v
):
--link-dest arg does not exist: full
If we then take a look at man rsync
under --link-dest
, we find:
如果我们再看看man rsync
under --link-dest
,我们会发现:
If DIR is a relative path, it is relative to the destination directory.
And there it is. full
is relative to the current directory. Relative to the destination directory, it would be ../full
.
就在那里。full
相对于当前目录。相对于目标目录,它将是../full
.
If you try again with rsync -avh --link-dest=../full orig/ orig_1
, you get what you expect:
如果你再试一次rsync -avh --link-dest=../full orig/ orig_1
,你会得到你所期望的:
$ du -sh *
149M full
149M orig
232K orig_1
$ du -sh .
298M .
Note that, when counted individually, the directories still appear take up the full space:
请注意,当单独计算时,目录仍然会占据整个空间:
$ du -sh orig_1
149M orig_1
This is because du
keeps track of files it's already seen, and avoids counting them twice.
这是因为du
跟踪它已经看到的文件,并避免将它们计算两次。
回答by rjmunro
--link-dest
takes a path relative to the destination. You want --link-dest=../orig
.
--link-dest
采取相对于目的地的路径。你要--link-dest=../orig
。
回答by Barmar
Standard Unix filesystems do not allow hard links to directories, except for the special .
and ..
links. --link-dest
only creates hard links for files, the rest of the directory structure is recreated as real directories.
标准 Unix 文件系统不允许硬链接到目录,除了特殊.
和..
链接。--link-dest
只为文件创建硬链接,目录结构的其余部分被重新创建为真正的目录。
And even if hard links were allowed to directories, du
would still show the full size of each link. When using hard links, there's no distinction between the original and the link, they're each just names that refer to a particular inode, and du
would scan them equivalently.
即使允许硬链接到目录,du
仍会显示每个链接的完整大小。使用硬链接时,原始链接和链接之间没有区别,它们都只是引用特定 inode 的名称,并且du
会等效地扫描它们。