Since the beginning the standard UNIX/Linux systems support sparse files, this is a file which contains unused space that is unallocated until needed. To review, to generate via a C program: create a file, position to 2G, write ONE byte, close file. Doing an ls -l shows the size to be 2G....however ls -ls shows the size in blocks to be closer to a one byte file. If you logically access the file (i.e. cp sparse_file xxx) the resulting file xxx will indeed contain a fully allocated 2Gbytes.

I have created sparse files in the past as a testing vehicle for some of applications. However, their existence has caused a few problems.

The important problem is that outside of the 'dump' program, backup programs and general procedures access these type of files logically and thus for a 1 byte sparse file one gets a backup w/ 2G of 0'd data. This has caused some upset backup folks when I do this.

Any good solutions for this type of situation?

link|improve this question

50% accept rate
sorry I mispelled Linux in the title. :-( – mdpc Aug 14 '09 at 1:23
Pro Tip: You don't need a custom program to create a sparse file, just dd: "dd if=/dev/zero of=sparse bs=1G seek=2 count=0". – MikeyB Aug 14 '09 at 4:30
or "truncate -s 1G sparse" – Pontus Sep 1 '10 at 18:41
feedback

4 Answers

up vote 3 down vote accepted

GNU Tar has the --sparse (-S) options that make working with spares files simple.

link|improve this answer
feedback

Use a backup program that is capable of detecting and handling sparse files correctly. There's plenty of them around (a la Jeremy's suggestion of tar with -S), just make it a checklist item on your backup system evaluation.

link|improve this answer
feedback

rsync-based backup programs should be able to handle space files just fine (rsync has --sparce/-S options)

link|improve this answer
feedback

The star program is much faster for sparse files than GNU tar. It requires the -sparse option when handling such files. For just plain copying use cp --sparse=auto

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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