General
cancel
Showing results for 
Search instead for 
Did you mean: 

How to put more than one tar file on a tape

Andrew Kaplan
Super Advisor

How to put more than one tar file on a tape

Hi there --

I have two directories that I would like to back up to tape using tar. I need to keep them as separate files.

What would be the correct command syntax to use in order to have two separate tar files on a single tape? Thanks.
A Journey In The Quest Of Knowledge
6 REPLIES
TTr
Honored Contributor

Re: How to put more than one tar file on a tape

If you have space on disk you can tar the two dirctories to tar files on disk and then put them to tape. Then extract either one of them in a single command.

Otherwise you can do the following

cd 1stdirectory
tar cvf /dev/rmt/Xn .
cd 2nddirectory
tar cvf /dev/rmt/X .

Where X is your tape drive device number. Note the use of the "n" in the "rmtXn" in the first tar command. This is very important to use and is for the "no rewind" tape device and leaves the tape at the end of the first tar file.

I try to avoid using this method because if you ever need to un-tar the second tar file from the tape you must remember that the tape contains two different tar files and skip forward the first tar file to be able to get to the second file and start un-tar-ing.

mt -f /dev/rmt/Xn fsf 1 (forward skip 1 file)
tar xvf /dev/rmt/X
James R. Ferguson
Acclaimed Contributor

Re: How to put more than one tar file on a tape

Hi:

Given that they are separate directories I don't see the need to keep them as separate archives.

You could even 'tar' them using absolute paths and then stipe those paths during a restoration using 'pax' to restore into a different directory should that be necessary. For example:

# tar -cvf /dev/rmt/0m /etc/rc.config.d /sbin/init.d

# mkdir /tmp/etc
# cd /tmp/etc && pax -r -s '|/etc/*|./|' -f /dev/rmt/0m

...to "un-tar" the '/etc/rc.config.d' into '/tmp/etc/rc.config.d'.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: How to put more than one tar file on a tape

>JRF: Given that they are separate directories I don't see the need to keep them as separate archives.

Right.

>You could even 'tar' them using absolute paths

You can also use tar's -C to store them both as relative:
tar -cf tape-device -C /path1 . -C /path2 .

>pax -r -s '|/etc/*|./|' -f /dev/rmt/0m
>to "un-tar" /etc/rc.config.d into /tmp/etc/rc.config.d.

Won't this also read /sbin/init.d back on itself? I.e. you need to add /etc/rc.config.d to the end of pax to select which to restore.
James R. Ferguson
Acclaimed Contributor

Re: How to put more than one tar file on a tape

Hi (again):

> Dennis: Won't this also read /sbin/init.d back on itself? I.e. you need to add /etc/rc.config.d to the end of pax to select which to restore.

Ah, yes, good catch! Thanks.

# cd /tmp/etc && pax -v -r -s '|/etc/*|./|' -f /dev/rmt/0m /etc/rc.config.d

...would extract only '/etc/rc.config.d' into '/tmp/etc'. That is, strip the absolute path and substitute a different directory as the destination.

Notice too, that I added the verbose ('-v') option to trace *exactly* what was restored. This would have immediately uncovered the unintentional recovery action caught by Dennis :-).

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: How to put more than one tar file on a tape

>JRF: that I added the verbose ('-v') option to trace *exactly* what was restored.

I think if you leave off -r, you can see what will be restored and see what the -s will do.
Dennis Handly
Acclaimed Contributor

Re: How to put more than one tar file on a tape

>ME: see what the -s will do.

It ignores the -s when doing a list.