如何在 Linux ext4 上比较两个文件的属性

All*_*rdt 4 linux backup stat files file-comparison

cmp(1) 当然会告诉我两个文件的内容是否相同,但为了测试从备份恢复,我还想比较相关的 (!) 文件属性。

所以如果我做了一些简单的事情

mv foo.bar foo.bar.save
deja-dup --restore foo.bar # or some other backup tool
Run Code Online (Sandbox Code Playgroud)

我如何比较 foo.bar 和 foo.bar.save 的属性并在 shell 脚本(或类似脚本)中测试是否足够相等。我可以

stat foo.bar{,.save}
Run Code Online (Sandbox Code Playgroud)

并手动检查输出,记住忽略 inode、atime 和 ctime(以及链接计数,出于某种原因?),但这很容易出错。某处是否有包含 SELinux 和其他属性的 cmp-with-attributes 工具?必须在 Fedora 和 ext4 文件系统上工作;理想情况下,在“所有”系统上。我需要在 perl 中修改一些东西吗?

(如果您不测试它们是否正常工作,则备份毫无意义。)

Sté*_*las 6

getallattr() {
  lsattr -d -- "$1" | cut -d ' ' -f1
  getfattr -dm- -- "$1" | tail -n +2 | sort
  stat -c '%u %g %a %s %x %y' -- "$1"
}
Run Code Online (Sandbox Code Playgroud)

检索所有属性(至少是那些可以轻松恢复的属性)。您还可以在其中包含 md5sum。

然后做

diff <(getallattr file1) <(getallattr file2)
Run Code Online (Sandbox Code Playgroud)

(ksh93、zsh、bash 语法)。