Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

cmp(1) will of course tell me if the contents of two files are identical, but in order to test restoring from backups I also wanted to compare the relevant (!) file attributes.

So if I did something simple like

mv foo.bar foo.bar.save
deja-dup --restore foo.bar # or some other backup tool

how do I compare the attributes of foo.bar and foo.bar.save and test for sufficient equality in a shell script (or similar). I can do

stat foo.bar{,.save}

and manually inspect the output remembering to ignore inode, atime, and ctime (as well as link count, for some reason?), but this is error prone. Is there a cmp-with-attributes tool somewhere which include SELinux and other attributes? Must work on Fedora and ext4 file systems; ideally on "all" systems. Do I need to hack something up in perl?

(No point having backups if you don't test that they work right.)

share|improve this question
1  
stat has two options, -c or --format, and --printf, that you can use to make it print the data you are interested in, in the format you want, so you can later compare it with diff or another tool. –  angus Aug 29 '12 at 9:03

1 Answer 1

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

To retrieve all the attributes (at least those that can easily be restored). You could also include the md5sum in there.

And then do

diff <(getallattr file1) <(getallattr file2)

(ksh93, zsh, bash syntax).

share|improve this answer
    
"getfattr -dm -" already takes care of ACLs, so no need for an extra command. –  Stéphane Chazelas Aug 30 '12 at 5:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.