Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Next: , Previous: Many, Up: Media


9.6 Using Multiple Tapes

Often you might want to write a large archive, one larger than will fit on the actual tape you are using. In such a case, you can run multiple tar commands, but this can be inconvenient, particularly if you are using options like --exclude=pattern or dumping entire file systems. Therefore, tar supports multiple tapes automatically.

Use --multi-volume (-M) on the command line, and then tar will, when it reaches the end of the tape, prompt for another tape, and continue the archive. Each tape will have an independent archive, and can be read without needing the other. (As an exception to this, the file that tar was archiving when it ran out of tape will usually be split between the two archives; in this case you need to extract from the first archive, using --multi-volume, and then put in the second tape when prompted, so tar can restore both halves of the file.)

GNU tar multi-volume archives do not use a truly portable format. You need GNU tar at both ends to process them properly.

When prompting for a new tape, tar accepts any of the following responses:

?
Request tar to explain possible responses
q
Request tar to exit immediately.
n file name
Request tar to write the next volume on the file file name.
!
Request tar to run a subshell. This option can be disabled by giving --restrict command line option to tar.
y
Request tar to begin writing the next volume.

(You should only type ‘y’ after you have changed the tape; otherwise tar will write over the volume it just finished.)

If you want more elaborate behavior than this, give tar the --info-script=script-name (--new-volume-script=script-name, -F script-name) option. The file script-name is expected to be a program (or shell script) to be run instead of the normal prompting procedure. It is executed without any command line arguments. Additional data is passed to it via the following environment variables:

TAR_VERSION
GNU tar version number.


TAR_ARCHIVE
The name of the archive tar is processing.


TAR_VOLUME
Ordinal number of the volume tar is about to start.


TAR_SUBCOMMAND
Short option describing the operation tar is executed. See Operations, for a complete list of subcommand options.


TAR_FORMAT
Format of the archive being processed. See Formats, for a complete list of archive format names.

The info script can instruct tar to use new archive name, by writing in to file descriptor 3 (see below for an example).

If the info script fails, tar exits; otherwise, it begins writing the next volume.

The method tar uses to detect end of tape is not perfect, and fails on some operating systems or on some devices. You can use the --tape-length=size (-L size) option if tar can't detect the end of the tape itself. This option selects --multi-volume (-M) automatically. The size argument should then be the usable size of the tape in units of 1024 bytes. But for many devices, and floppy disks in particular, this option is never required for real, as far as we know.

The volume number used by tar in its tape-change prompt can be changed; if you give the --volno-file=file-of-number option, then file-of-number should be an unexisting file to be created, or else, a file already containing a decimal number. That number will be used as the volume number of the first volume written. When tar is finished, it will rewrite the file with the now-current volume number. (This does not change the volume number written on a tape label, as per label, it only affects the number used in the prompt.)

If you want tar to cycle through a series of files or tape drives, there are three approaches to choose from. First of all, you can give tar multiple --file options. In this case the specified files will be used, in sequence, as the successive volumes of the archive. Only when the first one in the sequence needs to be used again will tar prompt for a tape change (or run the info script). Secondly, you can use the ‘n’ response to the tape-change prompt, and, finally, you can use an info script, that writes new archive name to file descriptor. The following example illustrates this approach:

     #! /bin/sh
     echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
     
     name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
     case $TAR_SUBCOMMAND in
     -c)       ;;
     -d|-x|-t) test -r ${name:-$TAR_ARCHIVE}-$TAR_VOLUME || exit 1
     	  ;;
     *)        exit 1
     esac
     
     echo ${name:-$TAR_ARCHIVE}-$TAR_VOLUME >&3

Each volume of a multi-volume archive is an independent tar archive, complete in itself. For example, you can list or extract any volume alone; just don't specify --multi-volume (-M). However, if one file in the archive is split across volumes, the only way to extract it successfully is with a multi-volume extract command --extract --multi-volume (-xM) starting on or before the volume where the file begins.

For example, let's presume someone has two tape drives on a system named /dev/tape0 and /dev/tape1. For having GNU tar to switch to the second drive when it needs to write the second tape, and then back to the first tape, etc., just do either of:

     $ tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 files
     $ tar cMff /dev/tape0 /dev/tape1 files

 
 
  Published under the terms of the GNU General Public License Design by Interspire