arcull
arcull

Reputation: 281

Why does 7z create different files?

I'm using 7z command in bash script to create a 7z archive for backup purposes. My script does also check if this newly created 7z archive exists in my backup folder and if it does, I go and run md5sum to see if content differs. So if the archive file doesn't exits yet or the md5sum differs from the previous I copy it to my backup folder. So I tried a simple example to test the script, but the problem is that I sometimes get different md5sum for the same folder I am compressing. Why is that so? Is there any other reliable way of checking if file content differs? The commands are simple:

SourceFolder="/home/user/Documents/"
for file in $SourceFolder*
do
  localfile=${file##*/}
  7z a -t7z "$SourceFolder${localfile}.7z" "$file"
  md5value=`md5sum "$SourceFolder${localfile}.7z"|cut -d ' ' -f 1`

...copyinf files goes from here on...

Upvotes: 1

Views: 405

Answers (2)

arcull
arcull

Reputation: 281

I've partially solved this. It looks like it matters if you specify full path to the folder you are compressing or not. The resulting file is not the same. .This affects both 7z and tar.I mean like this: value1=$(tar -c /tmp/at-spi2/|md5sum|cut -d ' ' -f 1) value2=$(tar -c at-spi2/|md5sum|cut -d ' ' -f 1)

So obviously I'm doing this wrong. Is there a switch for 7z and tar which would remove absolute path?

Upvotes: 0

John Zwinck
John Zwinck

Reputation: 249193

The reliable way to check if two different losslessly compressed files have identical contents is to expand their contents and compare those (e.g. using md5sum). Comparing the compressed files is going to end badly sooner or later, regardless of which compression scheme you use.

Upvotes: 1

Related Questions