1837228 Members
2413 Online
110115 Solutions
New Discussion

Re: tar help

 
Randy_121
New Member

tar help

Here is the scenario:

A tar file (of /opt) was coptied from one system to another.

I want to untar this file to a directory say /tmp/opt instead of overwriting my /opt directory.

Can this be done?
What is the syntax I can use?

Thank you,

Randy
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor

Re: tar help

In general, backups with absolute pathnames are less than wise. With tar, unless you do some tricky chroot's, you are stuck. However, you can use the pax command (which understands tar, cpio, and pax formats) to restore the files with different pathnames. Man pax for details and pay attention to the -s option.
If it ain't broke, I can fix that.
Rick Garland
Honored Contributor

Re: tar help

How was this tar created - with absolute path or relative path?

Relative path, you were in the /opt directory and issued the tar command.
tar -cvf mytarball.tar *

In this case, you can go into the /tmp/opt directory and do the 'tar -xvf mytarball.tar'

If absolute path, you issued the tar command as such;
'tar -cvf /opt'

In this case, doing an un-tar will overwrite the /opt directory, not a wise idea. Doesn't matter what the CWD is.

If you have an absolute tarball, you can use the 'pax' utility
Ivan Ferreira
Honored Contributor

Re: tar help

I don't have HP-UX to test but some tar implementations have an option to strip the initial / from the file names when restoring.

In Tru64 is "s" option. If you don't have that option, you should create the tarfile using relative path.

cd /opt
tar cvf /backup/tarfile ./*
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Muthukumar_5
Honored Contributor

Re: tar help

You are having absolute path from / directory. You can do like that.

# tar -tvf

You can get details. If it is absolute then move /opt contents related with tarfile with .old notation.

Extract contents and then move it to /tmp/opt. You can not move with tar to all files.

hth.
Easy to suggest when don't know about the problem!
KVK
Valued Contributor

Re: tar help

U can follow the TAR to restore the contents from othere server to where u want to restore .

I had experiance of restoring the /usr directory from one server to other server where /usr tampered .


I suggest you to restore it in /tmp location then check the file permissions are Ok .. If it's OK

Proceed to do a TAR in absolute path