@node extract
@section How to Extract Members from an Archive
-@UNREVISED
@cindex Extraction
@cindex Retrieving files from an archive
@cindex Resurrecting files from an archive
@node tar invocation
@chapter Invoking @GNUTAR{}
-@UNREVISED
This chapter is about how one invokes the @GNUTAR{}
command, from the command synopsis (@pxref{Synopsis}). There are
@node Long Options
@subsection Long Option Style
+@cindex long options
+@cindex options, long style
+@cindex options, GNU style
+@cindex options, mnemonic names
Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
dashes in a row, e.g., @option{--list}. The long names are more clear than
their corresponding short or old names. It sometimes happens that a
gives a fairly good set of hints about what the command does, even
for those not fully acquainted with @command{tar}.
+@cindex arguments to long options
+@cindex long options with mandatory arguments
Long options which require arguments take those arguments
immediately following the option name. There are two ways of
specifying a mandatory argument. It can be separated from the
@file{archive.tar} as argument by using any of the following notations:
@option{--file=archive.tar} or @option{--file archive.tar}.
+@cindex optional arguments to long options
+@cindex long options with optional arguments
In contrast, optional arguments must always be introduced using
an equal sign. For example, the @option{--backup} option takes
an optional argument specifying backup type. It must be used
@node Short Options
@subsection Short Option Style
+@cindex short options
+@cindex options, short style
+@cindex options, traditional
Most options also have a @dfn{short option} name. Short options start with
a single dash, and are followed by a single character, e.g., @option{-t}
(which is equivalent to @option{--list}). The forms are absolutely
The short option names are faster to type than long option names.
+@cindex arguments to short options
+@cindex short options with mandatory arguments
Short options which require arguments take their arguments immediately
following the option, usually separated by white space. It is also
possible to stick the argument right after the short option name, using
@w{@option{-f @var{archive-name}}} denote the option which indicates a
specific archive, here named @file{archive.tar}.
+@cindex optional arguments to short options
+@cindex short options with optional arguments
Short options which take optional arguments take their arguments
immediately following the option letter, @emph{without any intervening
white space characters}.
@node Old Options
@subsection Old Option Style
-@UNREVISED
+@cindex options, old style
+@cindex old option style
Like short options, @dfn{old options} are single letters. However, old options
must be written together as a single clumped set, without spaces separating
long option @option{--list}. So for example, the command @w{@samp{tar
cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
+@cindex arguments to old options
+@cindex old options with mandatory arguments
When options that need arguments are given together with the command,
all the associated arguments follow, in the same order as the options.
Thus, the example given previously could also be written in the old
@node Mixing
@subsection Mixing Option Styles
+@cindex options, mixing different styles
All three styles may be intermixed in a single @command{tar} command,
so long as the rules for each style are fully
respected@footnote{Before @GNUTAR{} version 1.11.6,
@command{tar} will only operate on archives that have a label matching
the pattern specified in @var{name}. @xref{Tape Files}.
+@opsummary{level}
+@item --level=@var{n}
+Force incremental backup of level @var{n}. As of @GNUTAR version
+@value{VERSION}, the option @option{--level=0} truncates the snapshot
+file, thereby forcing the level 0 dump. Other values of @var{n} are
+effectively ignored. @xref{--level=0}, for details and examples.
+
+The use of this option is valid only in conjunction with the
+@option{--listed-incremental} option. @xref{Incremental Dumps},
+for a detailed description.
+
@opsummary{listed-incremental}
@item --listed-incremental=@var{snapshot-file}
@itemx -g @var{snapshot-file}
@samp{Current %s is newer or same age}
@kwindex unknown-keyword
@cindex @samp{Ignoring unknown extended header keyword `%s'}, warning message
-@item unknown-keyword
+@item unknown-keyword
@samp{Ignoring unknown extended header keyword `%s'}
@end table
@node Operations
@subsection The Five Advanced @command{tar} Operations
-@UNREVISED
+@cindex basic operations
In the last chapter, you learned about the first three operations to
@command{tar}. This chapter presents the remaining five operations to
@command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
@node append
@subsection How to Add Files to Existing Archives: @option{--append}
-@UNREVISED
+@cindex appending files to existing archive
@opindex append
If you want to add files to an existing archive, you don't need to
create a new archive; you can use @option{--append} (@option{-r}).
member will end up being extracted, as it will replace the one
extracted before it, and so on.
+@cindex extracting @var{n}th copy of the file
+@xopindex{occurrence, described}
There exists a special option that allows you to get around this
behavior and extract (or list) only a particular copy of the file.
This is @option{--occurrence} option. If you run @command{tar} with
@cindex Members, replacing with other members
@cindex Replacing members with other members
+@xopindex{delete, using before --append}
If you want to replace an archive member, use @option{--delete} to
-delete the member you want to remove from the archive, , and then use
+delete the member you want to remove from the archive, and then use
@option{--append} to add the member you want to be in the archive. Note
that you can not change the order of the archive; the most recently
added member will still appear last. In this sense, you cannot truly
@node appending files
@subsubsection Appending Files to an Archive
-@UNREVISED
@cindex Adding files to an Archive
@cindex Appending files to an Archive
@cindex Archives, Appending files to
+@opindex append
The simplest way to add a file to an already existing archive is the
@option{--append} (@option{-r}) operation, which writes specified
@node multiple
@subsubsection Multiple Members with the Same Name
+@cindex members, multiple
+@cindex multiple members
You can use @option{--append} (@option{-r}) to add copies of files
which have been updated since the archive was created. (However, we
@node update
@subsection Updating an Archive
-@UNREVISED
@cindex Updating an archive
-
@opindex update
+
In the previous section, you learned how to use @option{--append} to
add a file to an existing archive. A related operation is
@option{--update} (@option{-u}). The @option{--update} operation
@node how to update
@subsubsection How to Update an Archive Using @option{--update}
+@opindex update
You must use file name arguments with the @option{--update}
(@option{-u}) operation. If you don't specify any files,
@node delete
@subsection Removing Archive Members Using @option{--delete}
-@UNREVISED
@cindex Deleting files from an archive
@cindex Removing files from an archive
@node compare
@subsection Comparing Archive Members with the File System
@cindex Verifying the currency of an archive
-@UNREVISED
@opindex compare
The @option{--compare} (@option{-d}), or @option{--diff} operation compares
@node extract options
@section Options Used by @option{--extract}
-@UNREVISED
+@cindex options for use with @option{--extract}
@xopindex{extract, additional options}
The previous chapter showed how to use @option{--extract} to extract
@node Reading
@subsection Options to Help Read Archives
@cindex Options when reading archives
-@UNREVISED
@cindex Reading incomplete records
@cindex Records, incomplete
@node Backups
@chapter Performing Backups and Restoring Files
-@UNREVISED
+@cindex backups
-@GNUTAR{} is distributed along with the scripts
-which the Free Software Foundation uses for performing backups. There
-is no corresponding scripts available yet for doing restoration of
-files. Even if there is a good chance those scripts may be satisfying
-to you, they are not the only scripts or methods available for doing
+@GNUTAR{} is distributed along with the scripts for performing backups
+and restores. Even if there is a good chance those scripts may be
+satisfying to you, they are not the only scripts or methods available for doing
backups and restore. You may well create your own, or use more
sophisticated packages dedicated to that purpose.
Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
Automatic Network Disk Archiver), a backup system developed by James
da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
-This is free software, and it is available at these places:
-
-@smallexample
-http://www.cs.umd.edu/projects/amanda/amanda.html
-ftp://ftp.cs.umd.edu/pub/amanda
-@end smallexample
+This is free software, and it is available from @uref{http://www.amanda.org}.
@FIXME{
backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
@var{snapshot-file}}) and @option{--incremental} (@option{-G}).
-@opindex listed-incremental
+@xopindex{listed-incremental, described}
The option @option{--listed-incremental} instructs tar to operate on
an incremental archive with additional metadata stored in a standalone
file, called a @dfn{snapshot file}. The purpose of this file is to help
/usr}
@end smallexample
+@anchor{--level=0}
+@xopindex{level, described}
+You can force @samp{level 0} backups either by removing the snapshot
+file before running @command{tar}, or by supplying the
+@option{--level=0} option, e.g.:
+
+@smallexample
+$ @kbd{tar --create \
+ --file=archive.2.tar \
+ --listed-incremental=/var/log/usr.snar-0 \
+ --level=0 \
+ /usr}
+@end smallexample
+
Incremental dumps depend crucially on time stamps, so the results are
unreliable if you modify a file's time stamps during dumping (e.g.,
with the @option{--atime-preserve=replace} option), or if you set the clock
@node Choosing
@chapter Choosing Files and Names for @command{tar}
-@UNREVISED
Certain options to @command{tar} enable you to specify a name for your
archive. Other options let you decide which files to include or exclude
@node file
@section Choosing and Naming Archive Files
-@UNREVISED
@cindex Naming an archive
@cindex Archive Name
@cindex Choosing an archive file
@cindex Where is the archive?
+@opindex file
By default, @command{tar} uses an archive file name that was compiled when
it was built on the system; usually this name refers to some physical
tape drive on the machine. However, the person who installed @command{tar}
@cindex Reading file names from a file
@cindex Lists of file names
@cindex File Name arguments, alternatives
+@cindex @command{find}, using with @command{tar}
Instead of giving the names of files or archive members on the command
line, you can put the names into a file, and then use the
@option{--files-from=@var{file-of-names}} (@option{-T
@node exclude
@section Excluding Some Files
-@UNREVISED
@cindex File names, excluding files by
@cindex Excluding files by name and pattern
@cindex Excluding files by file system
+@opindex exclude
+@opindex exclude-from
To avoid operating on files whose names match a particular pattern,
use the @option{--exclude} or @option{--exclude-from} options.
@node after
@section Operating Only on New Files
-@UNREVISED
@cindex Excluding file by age
@cindex Data Modification time, excluding files by
modification of the file's data (rather than status
changes), then use the @option{--newer-mtime=@var{date}} option.
+@cindex --after-date and --update compared
+@cindex --newer-mtime and --update compared
You may use these options with any operation. Note that these options
differ from the @option{--update} (@option{-u}) operation in that they
allow you to specify a particular date against which @command{tar} can
@node recurse
@section Descending into Directories
-@UNREVISED
@cindex Avoiding recursion in directories
@cindex Descending directories, avoiding
@cindex Directories, avoiding recursion
@cindex Recursion in directories, avoiding
-@FIXME{arrggh! this is still somewhat confusing to me. :-< }
-
Usually, @command{tar} will recursively explore all directories (either
those given on the command line or through the @option{--files-from}
option) for the various files they contain. However, you may not always
want @command{tar} to act this way.
@opindex no-recursion
+@cindex @command{find}, using with @command{tar}
The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
into specified directories. If you specify @option{--no-recursion}, you can
-use the @command{find} utility for hunting through levels of directories to
+use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
+utility for hunting through levels of directories to
construct a list of file names which you could then pass to @command{tar}.
@command{find} allows you to be more selective when choosing which files to
archive; see @ref{files}, for more information on using @command{find} with
-@command{tar}, or look.
+@command{tar}.
@table @option
@item --no-recursion
@node one
@section Crossing File System Boundaries
@cindex File system boundaries, not crossing
-@UNREVISED
@command{tar} will normally automatically cross file system boundaries in
order to archive files which are part of a directory tree. You can
@node absolute
@subsection Absolute File Names
-@UNREVISED
+@cindex absolute file names
+@cindex file names, absolute
+
+By default, @GNUTAR{} drops a leading @samp{/} on
+input or output, and complains about file names containing a @file{..}
+component. There is an option that turns off this behavior:
@table @option
@opindex absolute-names
containing a @file{..} file name component.
@end table
-By default, @GNUTAR{} drops a leading @samp{/} on
-input or output, and complains about file names containing a @file{..}
-component. This option turns off this behavior.
-
When @command{tar} extracts archive members from an archive, it strips any
leading slashes (@samp{/}) from the member name. This causes absolute
member names in the archive to be treated as relative file names. This
@FIXME{Should be an example in the tutorial/wizardry section using this
to transfer files between systems.}
-@FIXME{Is write access an issue?}
-
@table @option
@item --absolute-names
Preserves full file names (including superior directory names) when
@end table
-@FIXME{this is still horrible; need to talk with dan on monday.}
-
@command{tar} prints out a message about removing the @samp{/} from
file names. This message appears once per @GNUTAR{}
invocation. It represents something which ought to be told; ignoring
@node Attributes
@section Handling File Attributes
-@UNREVISED
+@cindex atrributes, files
+@cindex file attributes
When @command{tar} reads files, it updates their access times. To
avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
reset the access time retroactively or avoid changing it in the first
place.
-Handling of file attributes
-
@table @option
@opindex atime-preserve
@item --atime-preserve
@node hard links
@subsection Hard Links
-@UNREVISED{}
@cindex File names, using hard links
@cindex hard links, dereferencing
@cindex dereferencing hard links
@cindex large values
@cindex future time stamps
@cindex negative time stamps
-@UNREVISED{}
+@UNREVISED
The above sections suggest to use @samp{oldest possible} archive
format if in doubt. However, sometimes it is not possible. If you
@node Blocking
@section Blocking
-@UNREVISED
+@cindex block
+@cindex record
@dfn{Block} and @dfn{record} terminology is rather confused, and it
is also confusing to the expert reader. On the other hand, readers
@end table
-@FIXME{Is there a better way to frob the spacing on the list?}
-
If you don't specify a @var{tapename}, @command{mt} uses the environment
variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
the default device specified in your @file{sys/mtio.h} file
@node Tape Files
@subsection Tape Files
+@cindex labeling archives
+@opindex label
@UNREVISED
To give the archive a name which will be recorded in it, use the
distribution tarballs. @xref{Formats,v7}, for the detailed discussion
of this issue and its implications.
-@FIXME{Change the first argument to tar-formats when the new Automake is
-out. The proposition to add @anchor{} to the appropriate place of its
-docs was accepted by Automake people --Sergey 2006-05-25}.
-@xref{Options, tar-v7, Changing Automake's Behavior,
+@xref{Options, tar-formats, Changing Automake's Behavior,
automake, GNU Automake}, for a description on how to use various
archive formats with @command{automake}.
/* Output index file name. */
GLOBAL char const *index_file_name;
+/* Opaque structure for keeping directory meta-data */
+struct directory;
+
/* Structure for keeping track of filenames and lists thereof. */
struct name
{
struct name *next; /* Link to the next element */
struct name *prev; /* Link to the previous element */
+
+ char *name; /* File name or globbing pattern */
+ size_t length; /* cached strlen (name) */
+ int matching_flags; /* wildcard flags if name is a pattern */
+
int change_dir; /* Number of the directory to change to.
Set with the -C option. */
uintmax_t found_count; /* number of times a matching file has
been found */
- int matching_flags; /* this name is a regexp, not literal */
- size_t length; /* cached strlen(name) */
- char *name;
-
- /* The following members are used for incremental dumps only */
- char const *dir_contents; /* directory contents */
+ /* The following members are used for incremental dumps only,
+ if this struct name represents a directory;
+ see incremen.c */
+ struct directory *directory;/* directory meta-data and contents */
struct name *parent; /* pointer to the parent hierarchy */
struct name *child; /* pointer to the first child */
struct name *sibling; /* pointer to the next sibling */
- char *caname; /* canonical name */
+ char *caname; /* canonical name */
};
/* Obnoxious test to see if dimwit is trying to dump the archive. */
char *dumpdir_next (dumpdir_iter_t itr);
char *dumpdir_first (dumpdir_t dump, int all, dumpdir_iter_t *pitr);
-const char *scan_directory (char *dir_name, dev_t device, bool cmdline);
-const char *append_incremental_renames (const char *dump);
+struct directory *scan_directory (char *dir, dev_t device, bool cmdline);
+void name_fill_directory (struct name *name, dev_t device, bool cmdline);
+const char *directory_contents (struct directory *dir);
+const char *safe_directory_contents (struct directory *dir);
+
+void rebase_directory (struct directory *dir,
+ const char *samp, size_t slen,
+ const char *repl, size_t rlen);
+
+void append_incremental_renames (struct directory *dir);
void read_directory_file (void);
void write_directory_file (void);
void purge_directory (char const *directory_name);
void list_dumpdir (char *buffer, size_t size);
void update_parent_directory (const char *name);
-void rebase_directory (const char *name, size_t old_prefix_len,
- const char *old_prefix,
- const char *new_prefix);
size_t dumpdir_size (const char *p);
bool is_dumpdir (struct tar_stat_info *stat_info);
size_t size_from_header (const char *buf, size_t size);
time_t time_from_header (const char *buf, size_t size);
uid_t uid_from_header (const char *buf, size_t size);
-uintmax_t uintmax_from_header (const char * buf, size_t size);
+uintmax_t uintmax_from_header (const char *buf, size_t size);
void list_archive (void);
void print_for_mkdir (char *dirname, int length, mode_t mode);
int unquote_string (char *str);
char *zap_slashes (char *name);
char *normalize_filename (const char *name);
+void replace_prefix (char **pname, const char *samp, size_t slen,
+ const char *repl, size_t rlen);
void code_ns_fraction (int ns, char *p);
char const *code_timespec (struct timespec ts, char *sbuf);
}
\f
-static void
-replace_prefix (char **pname, const char *samp, size_t slen,
- const char *repl, size_t rlen)
-{
- char *name = *pname;
- size_t nlen = strlen (name);
- if (nlen > slen && memcmp (name, samp, slen) == 0 && ISSLASH (name[slen]))
- {
- if (rlen > slen)
- {
- name = xrealloc (name, nlen - slen + rlen + 1);
- *pname = name;
- }
- memmove (name + rlen, name + slen, nlen - slen + 1);
- memcpy (name, repl, rlen);
- }
-}
-
void
dirlist_replace_prefix (const char *pref, const char *repl)
{
}
#endif
-/* Find a directory entry for NAME. If first OLD_PREFIX_LEN
- bytes of its name match OLD_PREFIX, replace them with
- NEW_PREFIX. */
+/* If first OLD_PREFIX_LEN bytes of DIR->NAME name match OLD_PREFIX,
+ replace them with NEW_PREFIX. */
void
-rebase_directory (const char *name, size_t old_prefix_len,
- const char *old_prefix,
- const char *new_prefix)
+rebase_directory (struct directory *dir,
+ const char *old_prefix, size_t old_prefix_len,
+ const char *new_prefix, size_t new_prefix_len)
{
- struct directory *dir = find_directory (name);
- if (dir)
- replace_prefix (&dir->name, old_prefix, old_prefix_len,
- new_prefix, strlen (new_prefix));
+ replace_prefix (&dir->name, old_prefix, old_prefix_len,
+ new_prefix, new_prefix_len);
}
/* Return a directory entry for a given combination of device and inode
/* Recursively scan the given directory DIR.
DEVICE is the device number where DIR resides (for --one-file-system).
If CMDLINE is true, the directory name was explicitly listed in the
- command line. */
-const char *
+ command line.
+ Unless *PDIR is NULL, store there a pointer to the struct directory
+ describing DIR. */
+struct directory *
scan_directory (char *dir, dev_t device, bool cmdline)
{
char *dirp = savedir (dir); /* for scanning directory */
directory = procdir (name_buffer, &stat_data, device,
(cmdline ? PD_FORCE_INIT : 0),
&ch);
-
+
name_length = strlen (name_buffer);
if (! ISSLASH (name_buffer[name_length - 1]))
{
if (dirp)
free (dirp);
- return directory->dump ? directory->dump->contents : NULL;
+ return directory;
+}
+
+/* Return pointer to the contents of the directory DIR */
+const char *
+directory_contents (struct directory *dir)
+{
+ if (!dir)
+ return NULL;
+ return dir->dump ? dir->dump->contents : NULL;
}
+/* A "safe" version of directory_contents, which never returns NULL. */
const char *
-get_directory_contents (char *dir, dev_t device, bool force)
+safe_directory_contents (struct directory *dir)
{
- return scan_directory (dir, device, force);
+ const char *ret = directory_contents (dir);
+ return ret ? ret : "\0\0\0\0";
+}
+
+void
+name_fill_directory (struct name *name, dev_t device, bool cmdline)
+{
+ name->directory = scan_directory (name->name, device, cmdline);
}
\f
}
}
-const char *
-append_incremental_renames (const char *dump)
+void
+append_incremental_renames (struct directory *dir)
{
struct obstack stk;
size_t size;
struct directory *dp;
+ const char *dump;
if (dirhead == NULL)
- return dump;
+ return;
obstack_init (&stk);
+ dump = directory_contents (dir);
if (dump)
{
size = dumpdir_size (dump) - 1;
if (obstack_object_size (&stk) != size)
{
obstack_1grow (&stk, 0);
- dump = obstack_finish (&stk);
+ dumpdir_free (dir->dump);
+ dir->dump = dumpdir_create (obstack_finish (&stk));
}
- else
- obstack_free (&stk, NULL);
- return dump;
+ obstack_free (&stk, NULL);
}
\f