Next: , Previous: extract options, Up: operations


4.5 Backup options

GNU tar offers options for making backups of files before writing new versions. These options control the details of these backups. They may apply to the archive itself before it is created or rewritten, as well as individual extracted members. Other GNU programs (cp, install, ln, and mv, for example) offer similar options.

Backup options may prove unexpectedly useful when extracting archives containing many members having identical name, or when extracting archives on systems having file name limitations, making different members appear has having similar names through the side-effect of name truncation. (This is true only if we have a good scheme for truncated backup names, which I'm not sure at all: I suspect work is needed in this area.) When any existing file is backed up before being overwritten by extraction, then clashing files are automatically be renamed to be unique, and the true name is kept for only the last file of a series of clashing files. By using verbose mode, users may track exactly what happens.

At the detail level, some decisions are still experimental, and may change in the future, we are waiting comments from our users. So, please do not learn to depend blindly on the details of the backup features. For example, currently, directories themselves are never renamed through using these options, so, extracting a file over a directory still has good chances to fail. Also, backup options apply to created archives, not only to extracted members. For created archives, backups will not be attempted when the archive is a block or character device, or when it refers to a remote file.

For the sake of simplicity and efficiency, backups are made by renaming old files prior to creation or extraction, and not by copying. The original name is restored if the file creation fails. If a failure occurs after a partial extraction of a file, both the backup and the partially extracted file are kept.

--backup[=method]
Back up files that are about to be overwritten or removed. Without this option, the original versions are destroyed.

Use method to determine the type of backups made. If method is not specified, use the value of the VERSION_CONTROL environment variable. And if VERSION_CONTROL is not set, use the ‘existing’ method.

This option corresponds to the Emacs variable ‘version-control’; the same values for method are accepted as in Emacs. This option also allows more descriptive names. The valid methods are:

t
numbered
Always make numbered backups.
nil
existing
Make numbered backups of files that already have them, simple backups of the others.
never
simple
Always make simple backups.

--suffix=suffix
Append suffix to each backup file made with --backup. If this option is not specified, the value of the SIMPLE_BACKUP_SUFFIX environment variable is used. And if SIMPLE_BACKUP_SUFFIX is not set, the default is ‘~’, just as in Emacs.