1833832 Members
2042 Online
110063 Solutions
New Discussion

Re: tar question

 
Supporto Unix
Occasional Advisor

tar question

Hi all,

is this right for extract a specif directory from archive.tar

#dir to extract /data/pine and all subdir under /data/pine

tar xvf /dev/rmt/0m /data/pine

tar xvf /dev/rmt/0m /data/pine

Which is the correct one ?
Thanks
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: tar question

I'd not define the file /dev/rmt/0m

tar xv /data/pine

tar defaults to tape as a source for writing and reading.

Or

cd /data/pine

tar xv

But I don't have access to a UX box right now, so try the test command first.

cd /data/pine

tar tv

t is for test

or tar tvf /dev/rmt/0m /data/pine

See what's going to happen before you write something you might need to clean up.

Question. Is the original data source another machine? /data/pine directory perhaps?

Question. the two commands above seem to be duplicates, what difference am I missing?

Steve
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Jose Mosquera
Honored Contributor

Re: tar question

Hi,

This deppend of the way that was created in the source place.

If your default tape device is /dev/rmt/0m you can obviate "-f /dev/rmt/0m" option.

A tip for this is doing a tar tv, this ecreen output will show you the tar tape content.

Case 1: if your you see something as:
./root_dir/dir2/data/pine/etc...
this mean that tar have created in the source from "/" dir, so you need recover from "/". In this case, be careful with the rest of stored dirs, they could re-write some not wanted structure. tar xv ./root_dir/dir2/data/pine/

Case 2: if you see directly files that belong at the /data/pine dir structure, you must create first /data/pine tree, and then from there, execute "tar xv ." command.

In any case, to avoid risky situations, create a temporary dir with enough restoring space, then put inside and restore whole content by:
tar xv .

Important: protects the tape to avoid not wanted writing.

Rgds.
Jose Mosquera
Honored Contributor

Re: tar question

Hi again,

If you decide recover the whole content of the tape in a temporary directory, i.e:
#cd temporal
#tar xv .

When the recovery process concludes, simply moves requested tree (/data/pine) to the appropriate place.

Rgds.
Tim D Fulford
Honored Contributor

Re: tar question

tar x /data/pine
tar xv /data/pine
tar xvf /dev/rmt/0m /data/pine
tar -xvf /dev/rmt/0m /data/pine

All the above will extract /data/pine from /dev/rmt/0m (tape drive) to /data/pine.

Regards

Tim
-
Patrick Wallek
Honored Contributor

Re: tar question

As with everything in Unix, the answer is: It Depends!

The syntax you use to extract from a tar archive depends ENTIRELY on how the archive was created.

Here are 3 different exaples:

1) If the archive was created like this:

# tar -cvf /dev/rmt/0m /data/pine

Then you restore it like this:

# tar -xvf /dev/rmt/0m /data/pine

Note that your only option for restoring, unless you use 'pax' ('man pax' for more information), is to restore back to its original location, /data/pine.

2) If the archive was created like this:

# tar -cvf /dev/rmt/0m ./data/pine

Note the . in front of the directory name.

Then you restore it like this:

# tar -xvf /dev/rmt/0m ./data/pine

In this situation you can restore it to any sub-directory since it will restore using relative directory paths (remember the ./). This means it will created the data/pine directory structure in whatever directory you are currently in.

3) If the archive was created like this:

# tar -cvf /dev/rmt/0m data/pine

Then you restore it like this:

# tar -xvf /dev/rmt/0m data/pine

Again, since this is using relative paths, so when you restore the directory structure will be created in whatever directory you are currently in.

The best thing to do to figure out how to restore is to do a:

# tar -tvf /dev/rmt/0m

This will list the names of all the files on the tape. Kind of like a table of contents. See 'man tar' for more information.

When you see the output the 'tar -tvf' gives, you can then determine for certain which method above you can use to do the restore.

Good luck.