2

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?

3
  • sorry I mispelled Linux in the title. :-(
    – mdpc
    Aug 14, 2009 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, 2009 at 4:30
  • or "truncate -s 1G sparse"
    – Pontus
    Sep 1, 2010 at 18:41

4 Answers 4

3

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

2

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.

1

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

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .