Operating System - HP-UX
1754174 Members
3061 Online
108811 Solutions
New Discussion юеВ

Re: tar to different directory

 
Steven Chen_1
Super Advisor

tar to different directory

I want to tar xvf file to different directory from the original, but I can't.

for example:
tar tvf /dev/rmt/c0t0d0BEST, shows file on tape as /tmp/file1.

then:
tar xvf /dev/rmt/c0t0d0BEST /disk1/file1 would not copy file1 to /disk1 directory.

But I can tar xvf back to /tmp where the file1 being tar cvf from.

Can somebody helps?
Steve
10 REPLIES 10
Antoanetta Naghiu
Esteemed Contributor

Re: tar to different directory

cd in the desired directory and tar xvf /dev/rmt/0m
Alan Riggs
Honored Contributor

Re: tar to different directory

I believe you are working from a tape archive that was made with absolute pathnames. If so, the tar command has no way to redirect the extraction. This is one reason why I always recommend writing archives with relative pathnames.

All is not lost, though. I believe the pax command will be able to do a string replacement on the extraction path for you. Please see man pax for the syntax and details.
Steven Chen_1
Super Advisor

Re: tar to different directory

for all files to extract to desire location, that works.

but how about to get just some files instead of all of them from the tape?
Steve
Antoanetta Naghiu
Esteemed Contributor

Re: tar to different directory

Use fbackup or cpio, omniback. I've done it under cpio, fbackup, omniback, never under tar.
The documentation said that using
tar xvf archive file_name you can extract desired file... Ty it....
Alan Riggs
Honored Contributor

Re: tar to different directory

To specify a single file to be restored from an archive simply give it as a command line option:

tar vxf /dev/rmt/0m file/to_be.restored
Michael Hiron
New Member

Re: tar to different directory

The pax command should do what you require. Something like:

pax -r -v -s !/olddir!/newdir!gp -f Tape_Device_File

See man page of pax for more details.
Steven Chen_1
Super Advisor

Re: tar to different directory

I would like to know more on how to make tar files with relative pathname.

Example:

files location to be tar: /disk3/file1,file2...

I has done:
tar cvf /dev/rmt/c2t0d0BEST /disk3/file1,file2...

In order to get files back to any other location, what should I use to tar at the begining?
tar cvf /dev/rmt/c2t0d0BEST disk3 ? or any?


Thanks a lot.

Steve
Devbinder Singh Marway
Valued Contributor

Re: tar to different directory


Absolute backup(i.e. /test/files , you can restore from anywhere and it will restore in the correct directory , with relative backup you can specify where you want to restore files i.e (.file1 / ./test/file)

if you want to backup all the files in a directory ( relatively) :-

1. cd into the directory

tar cvbf 64 /dev/rmt/0m .
*when you look at the files on tape they will be .file1 .file2 .file3 etc..

However if you want to do a relative backup from root

cd /
tar cvbf 64 /dev/rmt/0m "./dir1/dir2"

on the tape files will be listed as

./dir1/dir2/file1 , ./dir1/dir2/file2 etcc

so to restore to say test1 dir , it will create direcries dir1,dir2 under test
where as the first method will restore files
in the directory you CD'ed into.

Basically a dot (.) means relative i.e. current directory
and / means absolute

To restore individual files or directories
put them in quotes i.e.

tar xvbf 64 /dev/rmt/0mn "./file2" "/tmp/ds"

one other thing is create a directory if you do not have spare tapes and create some dummy files and try out the tar command
so instead of using the tape device use a file name for the tar archive and view this later i.e. tar cvbf 64 testtar "files"
to view tar tvf testtar

hope this helps
Seek and you shall find

Re: tar to different directory

Hi,

Normally I would do the following:

cd
tar -cvf /dev/rmt/0m .
Note that there is a . (dot) at the the end, to indicate the current directory.
this way all the files and subsequent directories are on the tape, to reload them
in a desired directory,
cd
tar -xvf /dev/rmt/0m

The files in the tar are listed with a . (dot) at beginning, to indicate a relative pathname from the current directory.

Regards, Andre