ArGest Backup User Guide

⌘K
  1. Home
  2. Docs
  3. ArGest Backup User Guide
  4. Terminal Advanced Uses
  5. Handling Sparse Files: (-S threshold)

Handling Sparse Files: (-S threshold)

With the UNIX filesystem, it is possible to create files which take up much less space in the filesystem than their size would indicate. These files are generally known as sparse files, and commonly occur in database or scientific applications. A sparse file can be loosely defined as one in which large areas of null bytes are created by seeking to a particular file offset before writing any actual data. The following example shows creation of a sparse file using the UNIX dd command to create an empty file, seeking to an offset of 1M in the file, and then writing a string at that offset:

$ df
/ /dev/dsk/c0d0s0 20330 blocks 9670 i-nodes
/x /dev/dsk/c5d0s0 13242 blocks 7168 i-nodes
$ echo “End Of File” | dd of=sparsefile bs=1k seek=1k
0+1 blocks in
0+1 blocks out
$ ls -l sparsefile
-rw-rw-r— 1 fnf sys 1048588 Oct 5 09:50 sparsefile
$ od -c sparsefile
0000000 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
*
4000000 E n d O f F i l e \n
4000014
$ df
/ /dev/dsk/c0d0s0 20330 blocks 9670 i-nodes
/x /dev/dsk/c5d0s0 13236 blocks 7167 i-nodes

Note that the free space in the /x filesystem, where the sparse file was created, was 13242 blocks before creating the 1M sparse file, and 13236 blocks afterwards. Thus the sparse file actually uses only 6 disk blocks (each 512 bytes), or 3K bytes of actual disk space.

Now look what happens when we copy the sparse file to another file:

$ df
/ /dev/dsk/c0d0s0 20330 blocks 9670 i-nodes
/x /dev/dsk/c5d0s0 13230 blocks 7167 i-nodes
$ cp sparsefile bigfile
$ df
/ /dev/dsk/c0d0s0 20330 blocks 9670 i-nodes
/x /dev/dsk/c5d0s0 11170 blocks 7166 i-nodes
$ ls -l sparsefile bigfile
-rw-rw-r— 1 fnf sys 1048588 Oct 5 09:50 sparsefile
-rw-rw-r— 1 fnf sys 1048588 Oct 5 10:04 bigfile
$ od -c bigfile
0000000 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
*
4000000 E n d O f F i l e \n
4000014

The thing to note here is that when we copied the file, the process of copying the file did not preserve the sparseness of the file. The copy of the file named bigfile now actually takes up about 1M of disk space (2060 blocks). Note that BRU can be used to copy the file while preserving the sparseness, as given in an example earlier. From the viewpoint of a user process reading or writing the file, both files look identical, as is shown by the dump of the file using the UNIX od command. However, the original sparse file only uses 6 disk blocks and the copy uses 2060, quite a difference! BRU has a special option, the -S option, which turns on features that reduce the amount of archive space used by sparse files, and that preserve the sparseness of the file when it is extracted from the archive.