Operating System - HP-UX
1834165 Members
2439 Online
110064 Solutions
New Discussion

Re: Problems with pax and tar commands

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

Problems with pax and tar commands

HI,
I have a .tar file i.e file.tar which I'm trying to extract into a directory different from original path.

The original paths are:
/cs/home/projects/f1
/cs/home/projects/f2
/cs/home/disks/01
/cs/home/disks/02

using the command, the original paths were tar-ed as:
# tar -cvf file.tar /cs/home/projects/f1
(list continues for the remaining filesystems ...). The filesystems were archived with the absolute paths.

I need to extract the contents of file.tar into /project/restore filesystem.

I tried the following methods:
1)
#cd /project/restore
#tar -xvf file.tar
This caused the archived files to be extracted to its original path i.e. /cs/home/ filesystem area.

2)# cd /project/restore
# pax -r -f file.tar
pax:/cs/home/projects/f1 : The file/directory exists and will not be overwritten.
pax:/cs/home/projects/f2 :The file access permissions do not allow the specified action.

3) #cd /project/restore
#pax -r -s "/cs/project" -f file.tar
pax: 0511-660 A replacement string was not added : Bad delimeters
pax:/cs/home/projects/f1 : The file/directory exists and will not be overwritten.
pax:/cs/home/projects/f2 : The file access permissions do not allow the specified action.

For method (3), I tried reading the archive file.tar with all files rooted in /cs/ in the archive extracted relative to the current directory /project/restore.

Could anyone help me by pointing out where did I go wrong? How should I fix such errors?

Thanks
13 REPLIES 13
Michael Tully
Honored Contributor

Re: Problems with pax and tar commands

Hi,

There is no way to change a backup restore point on tar is it was backed up using an absolute path.

From the man page:
There is no way to restore an absolute path name to a relative position.

Regards
Michael
Anyone for a Mutiny ?
S.K. Chan
Honored Contributor
Solution

Re: Problems with pax and tar commands

Well your pax syntax is not quite right .. lets try this ..
# cd /project/restore
# pax -r -s ',^/cs/home/,,' -f file.tar -t
==> That will create dirs "projects" and "disks" in /project/restore and extract everything under those dirs.
OR you can run ..
# pax -r -s ',^/cs/home/projects/,,' -f file.tar -t
and
# pax -r -s ',^/cs/home/disks/,,' -f file.tar -t
==> which would create dirs "f1", "f2", "01" and "02" in /project/restore instead and extract everything under those dirs.

John Dvorchak
Honored Contributor

Re: Problems with pax and tar commands

There in lies the problem of creating a tar archive with absolute path names instead of relative pathnames.

As I see if you can either recreate the tar file using relative path names i.e. cd to the directory first then create the archive. Or take it to another system without the directory tree you have there and extract it then recreate it using relative path name.

Good luck
If it has wheels or a skirt, you can't afford it.
Michael Tully
Honored Contributor

Re: Problems with pax and tar commands

On second thought using pax:

Change directory to where you wish to start:
cd /mydir

# pax -rv -s'/^\///' < file.tar


Failing all of that you could doenload GNU tar from from the porting archive:

http://hpux.connect.org.uk/hppd/hpux/Gnu/tar-1.13.25/
Anyone for a Mutiny ?
John Dvorchak
Honored Contributor

Re: Problems with pax and tar commands

Ok once again S.K to the rescue, I like his idea a lot better than mine. Thanks for the pax lesson S.K.
If it has wheels or a skirt, you can't afford it.
Chern Jian Leaw
Regular Advisor

Re: Problems with pax and tar commands

Michael,
I tried your method:
#cd /project/restore
#pax -rv -s '/^\///'
It extracts the contents of file.tar into the /project/restore/cs/home...

However, it did not preserve the ownerships and permissions of /cs, /cs/home and /cs/home/projects.

I tried doing:
# cd /project/restore
# pax -rv -s '/^\///' -pe < file.tar
I used the -p and -e options to preserve the ownerships and permissions. However, this method seemed to have preserved ownerships and permissions of f1, d1, f2, d2 and not /cs/home/projects/ and /cs/home/disks.

Could you show me how such problems can be fixed?

Thanks

MANOJ SRIVASTAVA
Honored Contributor

Re: Problems with pax and tar commands

Hi

there is no way you can restore to some other path , waht can be tried in case you have space is to mount some disk under /cs/home and then restore the data


Manoj Srivastava
Chern Jian Leaw
Regular Advisor

Re: Problems with pax and tar commands

SK,
I tried your suggestions:
1)
# cd /project/restore
# pax -r -s ',^/cs/home/,,' -f file.tar -t
pax: /cs/home/projects/f1 : The file or directory exists and will not be overwritten.
pax: /cs/home/projects/f2 : The file access permissions do not allow the specified action.
pax: /cs/home/disks/01 : The file or directory exists and will not be overwritten.
pax: /cs/home/disks/02 : The file or directory exists and will not be overwritten.

2)
# pax -r -s ',^/cs/home/projects/,,' -f file.tar -t
and
# pax -r -s ',^/cs/home/disks/,,' -f file.tar -t
pax: /cs/home/projects/f1 : The file or directory exists and will not be overwritten.
pax: /cs/home/projects/f2 : The file access permissions do not allow the specified action.
pax: /cs/home/disks/01 : The file or directory exists and will not be overwritten.
pax: /cs/home/disks/02 : The file or directory exists and will not be overwritten.

Could you point out to me where did I go wrong?

Thanks

Ramkumar Devanathan
Honored Contributor

Re: Problems with pax and tar commands

hi,

try this -

1. login or su to root
2. mkdir /dir_to_extract_to (or whatever you decide is appropriate)
3. cd /dir_to_extract_to
4. cp tar binary into /dir_to_extract_to
5. create a device file using mknod into /dir_to_extract_to
6. ls -l /dev/rmt/0m

crw-rw-rw- 2 bin bin 205 0x050000 Jan 21 18:38 /dev/rmt/0m

7. mknod tape c 205 0x050000
8. chroot /dir_to_extract_to ./tar -xvf ./device /dirs_to_restore

- ramd.
HPE Software Rocks!
Frank Slootweg
Honored Contributor

Re: Problems with pax and tar commands

Is is unclear to me what the *full* target paths should be, so I will not go into that.

But, if these are really only four files, then why don't you interactively rename the paths via the "-i" option?
H.Merijn Brand (procura
Honored Contributor

Re: Problems with pax and tar commands

I'm just dropping in, but the remark 'there is no way to ...' is only true for HP's version of tar. GNU tar *can* do it. Better even, GNU tar *by default* strips of leading slashes, so just go to a (new) trash folder and untar using GNU tar and you're done.

Prebuilt GNU tar available for 11.00 and 10.20 on my ITRC site https://www.beepz.com/personal/merijn/ or http://www.cmve.net/~merijn/

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Chern Jian Leaw
Regular Advisor

Re: Problems with pax and tar commands

procura,
Thanks for the quick alternative/easy solution.

However, when I tried using gtar to un-tar file.tar from the relative position, I was not able to preserve the ownerships of original filesystems that were tar-ed into file.tar.

I tried using the options --same-owner and --preserve-permissions for gtar as follows:

1)
# cd /project/restore
#gtar -xv --same-owner --preserve-permissions -f file.tar
gtar:Cannot chown file cs/home/projects/f1 to uid 977 gid 4:Not owner
(The same error list continues for the remaining filesystems extracted).

2)
#cd /project/restore
# gtar -xv -m -p -f file.tar

Method (2) did not generate the errors as in method (1). However, method (2) did not preserve the ownerships of the files extracted.

Could you kindly point out to me where did I go wrong?

If you're familiar with pax, I'd certainly like to have your input on the usage of pax to preserve the ownerships/permissions.

Thanks


H.Merijn Brand (procura
Honored Contributor

Re: Problems with pax and tar commands

Before you restore, be sure that there are no 's'-bits on the directory where you restore in, that your umask = 00 and that you run as root. Resolve security issues after the restore

# cd /tmp
# mkdir tmp
# cd /tmp/tmp
# pwd
/tmp/tmp
# chmod 777 .
# gtar ......

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn