DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Working with files and directories

Retrieving deleted files

File versioning is the ability of a system to preserve and access old copies of a file. Traditionally, the UNIX system does not support file versioning: whenever the UNIX system updates a file, the preceding image of its contents is lost. Certain editors make a copy of a file before updating it, but this feature is specific to the individual utility, and usually restricts itself to the maintenance of the current file and a single backup version.

Keeping old versions of files

The SCO OpenServer system supports file versioning. The root user must configure it for a filesystem at the time of mounting by setting the MINVTIME and MAXVDEPTH kernel parameters. These respectively set the interval before a file is versioned and set the maximum number of versions maintained (or steps in the evolution of the file's contents). Setting these to 0 disables versioning. (See ``Versioning filesystems (undelete)'' for details.)

When file versioning is configured, you must then enable it for a specific directory using the -s option of the undelete(C) command, as follows:

   $ undelete -s /users/mike/source/user_guide
This command line switches on versioning for all the files in the directory called user_guide and any subsequent child directories.

When file versioning is configured and enabled, it makes the filesystem preserve a copy of a file's contents whenever it is overwritten or deleted. This is done silently. The number of versions preserved depends on the setting of MAXVDEPTH. These copies can be retrieved at a later date using undelete.

You can make versioning visible by setting the SHOWVERSIONS environment variable to 1, as follows:

   $ SHOWVERSIONS=1; export SHOWVERSIONS
Within a directory, you can create versions for a single file, irrespective of whether general versioning configuration or enabling has been carried out, using the undelete -v option, as follows:
   $ undelete -v chapter3


NOTE: File versions created in this way will always be visible, independently of the value of SHOWVERSIONS. However, when the filesystem is mounted with versioning enabled, file versions created using undelete -v will not be visible.

A versioned filename has the following syntax:

filename;version

The filename element follows the normal UNIX file naming rules, and is separated from the file version by a semicolon.

To see a list of all the existing versions of a file, use the undelete -l option, as follows:

   $ undelete -l magnolia.txt
   undelete magnolia: no versions
   $ undelete -l begonia.txt
   begonia.txt;1
   begonia.txt;2
   begonia.txt;3
Specifying a version identifier causes only that version to be used in the command line; the existing versions are accessible in the same way as separate normal files:
   $ cat homework.txt\;1
   Italian Assignment 3
   

C'era una volta, l'orsetto che viveva nella foresta al ovest ... $ cat homework.txt\;2 Italian Assignment 3

Tanti anni fa, l'orsetto che vivo' nella bosca verso ponente ...

Note that the semicolon is a shell metacharacter, and must be quoted in the context of versioning, using the backslash. See ``Regular expressions'' for more information on metacharacters and quoting.

Undeleting files

On traditional UNIX systems, once you have deleted a file, you cannot retrieve it, other than by searching through any existing backup tapes. The SCO OpenServer system undelete command makes this process much easier on versioned files. These exist in three combinations:

To undelete a file that was removed by mistake, make the previous version current. Although the file itself may have been removed, the versions are still accessible, as the following sequence shows:
   $ l
   -rw-r--r--   1 sallyp   accounts    3768 Oct 31 16:03 begonia.txt
   $ rm begonia.txt
   $ l
   total 0
   $ undelete begonia.txt
   $ l
   -rw-r--r--   1 sallyp   accounts    3768 Oct 31 16:04 begonia.txt
When you specify a filename without a version identifier, you retrieve the most recent version of the file.

However, it is possible to check how many versions are available, using the undelete -l option, as follows:

   $ undelete -l
   begonia.txt;1
   begonia.txt;2
   begonia.txt;3
You can use undelete to recover any available version, as follows:

   $ undelete begonia.txt\;2
   $ l
   -rw-r--r--   1 sallyp   accounts    3768 Oct 31 16:05 begonia.txt
This silently overwrites an existing version of the same file.
   $ undelete -i begonia.txt
   begonia.txt;3: ? y
   $ l
   -rw-r--r--   1 sallyp   accounts    3768 Oct 31 16:05 begonia.txt
The undelete -i option recovers the most recent version of the specified file. If the the file already exists, you must choose whether to overwrite it. In this case, the most recent version (number 3) of the file is retrieved but the earlier versions are discarded.
   $ undelete -l undelete begonia: no versions

Cleaning up your filesystem

File versioning is a useful tool, but it can have an adverse effect on the filesystem, as unneeded old versions of files can rapidly accumulate, reducing free space. It is important to remember that switching on versioning for a directory causes it to apply to all child directories as well. Therefore, directories should be regularly cleared of unwanted old file versions.

The undelete -p option ``purges'' specified files. This permanently deletes the existing versions (but not the file itself).

   $ undelete -l
   tulip;1
   tulip;2
   tulip;3
   tulip;4
   $ undelete -p tulip
   $ undelete -l
   : no versions
Versioning is inherited by child directories, so the following command line is useful for cleaning out a whole directory system:
   $ undelete -prd /users/mike/source/user_guide
The -r option specifies a recursive purge, while -d specifies the directory at which the operation is to commence.

Another useful option is -m, which takes a number of days as an argument.

   $ undelete -m+2
   $ undelete -m-2
   $ undelete -m2
These command lines respectively cause undelete to consider only files deleted more than, less than and exactly, two days ago.

In filesystems where versioning is widespread, the issue of free space may be crucial. Therefore, it is advisable to set up a crontab(C) job containing a command line like the following, which executes a forced recursive purge of all files deleted more than two days ago, starting at the directory /users:

   $ undelete -rpfm+2 /users
See ``Executing processes at regular intervals'' for details of the crontab command.
Next topic: Specifying command input and output
Previous topic: Finding files

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005