user1928596
user1928596

Reputation: 1753

retrieve sparse file from tar created without -S flag

I created a backup for a file then compressed it and store it using tar. At the time I didn't know it was a sparse file, So I didn't use the -S flag.

Now I am trying to retrieve the data, but I can't since when I extract I get a non sparse file.

Is their a way to retrieve that info, or is it lost for good ?

Thanks in advance.

Upvotes: 0

Views: 367

Answers (1)

mxmlnkn
mxmlnkn

Reputation: 2131

Sparsity information is kind of redundant. You can determine whether some parts of a file should be sparse by checking whether those parts only contain zeros.

head -c $(( 1024 * 1024 )) /dev/urandom  > foo
head -c $(( 1024 * 1024 )) /dev/zero  >> foo
head -c $(( 1024 * 1024 )) /dev/urandom  >> foo
stat foo
    Size: 3145728  Blocks: 6144
fallocate --dig-holes foo
stat foo
    Size: 3145728  Blocks: 4096

As you can see from the block count, making it sparse was successful, and all those block that were completely zeroed out have been successfully removed.

Upvotes: 0

Related Questions