0

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.

user1928596
  • 1,503
  • 16
  • 21

1 Answers1

0

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.

mxmlnkn
  • 1,887
  • 1
  • 19
  • 26