1820695 Members
2408 Online
109627 Solutions
New Discussion юеВ

TAR command options

 
SOLVED
Go to solution
Enrico Venturi
Super Advisor

TAR command options

Hello colleagues,
a very simple question:
I need to know the options to create an archive by the TAR command and to keep the files absolute pathname; I need also to know if/how is possible to restore an archive containing files in absolute pathname on an a specific directory in relative format, i.e.
tar ... /tmp/pippo/..... -> /tmp/pippo/ fileas are archived
tar xvf .... on /usr/ directory -> /usr/tmp/pippo/ files are extracted

thanks
Enrico
10 REPLIES 10
Mark Grant
Honored Contributor

Re: TAR command options

To do absolute paths just put absolute paths in the command

"tar cvf /dev/rmt/0mn /usr /home etc"

There is no way to restore these to relative directories if using standard HP-UX tar
Never preceed any demonstration with anything more predictive than "watch this"
Jeff Schussele
Honored Contributor

Re: TAR command options

Hi Enrico,

To keep absolute pathname, then just create the tar with that path - Ex:

tar cvf /path/to/file.tar /path/to/1stfile /path/to/2ndfile /path/to/3rdfile etc.

To extract this to a relative path you can't use the standard tar. Have to use a command like pax & I *think* GNU tar (gtar) can do this, but not positive.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Massimo Bianchi
Honored Contributor

Re: TAR command options

HI,
to create an archive:

tar cvf /ABSOLUTEPATH/FILENAME.tar

AFAIK once the tar is created with absolute pathnames you have NO WAY to revert it to relative, so it is always advisable to use a relative one.


There would be a workaround, but i do not think that you want to mess up with chroot ....

Massimo
Elmar P. Kolkman
Honored Contributor

Re: TAR command options

To restore in another directory, you can use the -C option of tar on HP-UX. But this will need an extra command in your case:
tar xvf -C /usr/tmp
mv /usr/tmp/usr /usr/tmp/pippo

(Haven't test this, but it should work.)

Unless I misunderstand, and you want only the files in /usr from a tarfile containing more. In that case you need to list the files you want to retrieve at the end of the command line, but this can give problems too many arguments. pax is then the way to go, and can also sove your directory-name-change problem with a rewrite rule.
Every problem has at least one solution. Only some solutions are harder to find.
Patrick Wallek
Honored Contributor

Re: TAR command options

As said, once you store files via tar with absolute paths, it is VERY difficult to restore them elsewhere. I try to NEVER use absolute paths with tar.

If you absolutely must restore something stored with absolute paths to a different directory, have a look at the 'pax' command. It does have the ability to do what you want. ('man pax' for more info.)

Something else you could do in your case is store the files as ./tmp/pippo (tar -cvf /dev/rmt/??? ./tmp/pippo) This would still give you your /tmp dirnmae, but make restoring much easier.

You could then do: cd /usr ; tar -xvf /dev/rmt/??? ./tmp/pippo

Good Luck.
Lorenzo Facello
Valued Contributor

Re: TAR command options

Hi,
tar cvf /path/files.tar /path/files_to_tar

...to restore
take a look to this attach!
Hope this helps!
Michael Schulte zur Sur
Honored Contributor
Solution

Re: TAR command options

Hi,

isnt pax able to rename a file path while extracting?

greetings,

Michael
Jordan Bean
Honored Contributor

Re: TAR command options

Think about obtaining Gnu tar which doesn't suffer this limitation by dropping the leading / from the paths.

As long as you use HP tar, the recommendation is to always use relative paths. For example:

cd / && tar c ./the/path/you/want

Until you've recycled all of your tapes with absolute paths, the only option you have for recovery is setup the target path for chroot.

In HP-UX 11.x, this should work:

mkdir /target/path
cd /target/path
mkdir bin lib
cp /usr/bin/tar bin
cp /usr/lib/{dld,libdld,libc}.sl lib

If tar were a static binary, this would have been more trivial.

You do not need to copy any tar files to this location if you plan to use standard input.

If you need access to a tape device, eg /dev/rmt/0m, then create the device file:

mkdir -p dev/rmt
mknod dev/rmt/0m c major minor

where the major and minor numbers are taken from ls -l /dev/rmt/0m. For example, on my system: mknod dev/rmt/0m c 205 0x041000


Then extract the archive via stdin this way (The only required absolute path here is /usr/bin/tar because chroot does not look in PATH for to find commands.):

su root -c "/usr/sbin/chroot /target/path /usr/bin/tar xf - < /path/to/tarfile"

James Lynch
Valued Contributor

Re: TAR command options

Jordon,

To your point on tar not being static. You are partically correct, the tar program in /usr/bin is dynamically linked, however, there is a static version of the tar command in /sbin. For that matter, all of the commands in /sbin are statically linked.

JL
Wild turkey surprise? I love wild turkey surprise!
Jordan Bean
Honored Contributor

Re: TAR command options

Thanks, James! I knew pax was there, but never thought to look for tar. Well, it was a good exercise.