1753834 Members
8205 Online
108806 Solutions
New Discussion юеВ

Tar Command....

 
SOLVED
Go to solution
Jonathan Caplette
Regular Advisor

Tar Command....

Hi guys,

I have a tape with an unknow tar file, so I want to extract it on the machine, but when I extract the tar file, the files in it try to be restored on the / filesystem, something that I don't want... What I want is to extract what's in the tar file into the /tmp directory for example... What I want to know is what is the tar command that will permit me to extract the file on my tape under another filesystem???

Thanks
Jonathan
7 REPLIES 7
MANOJ SRIVASTAVA
Honored Contributor

Re: Tar Command....

Hi Jonathan

Tar would restore the way it was abcked up supose you have give

tar cvf /etc/* then files will be stored in that path like

/etc/xxx
/etc/YYYY

so whenever you have to restore it back , it restores using the same path .Where as if you have backed it up by going into /etc and then using

tar cv * then it will just store the file name.

The way around to restore with PATH is to clear the directory in question , move it to some other place ,and then restore the tape.
Slightly cumbersome but it should work.


Manoj Srivastava
Magdi KAMAL
Respected Contributor

Re: Tar Command....

Hi Jonathan,

you may apply the following command :

tar -tf /dev/rmt/#m

this command lists only the names of files from the tape without any extraction of the files it selfs.

if The first character from these files id
/
then the backup on that tape is done with the absolute path ( which start referincing from the root directory "/") and there is no manner to restaure it to another place. The only place is it's real place.

Workaround :
As siad before, remove the directory that it will be overwrite with the content of the restaure to some where else ( saved directory) and
resture your backup and then manually remove the saved directory to it's original place.

Magdi
Jonathan Caplette
Regular Advisor

Re: Tar Command....

Thanks...

you make me think to something.. I've made symbolic link to another filesystem... :)

so it solved my probleme!!! :)
Bill Hassell
Honored Contributor

Re: Tar Command....

There's actually a couple of ways to restore a tar tape to another directory when absolute paths are stored on the tape:

1. Use pax and the -s option. The man page shows an example of how to restore /usr files on tape to the current working directory.

2. Use chroot (change root directory) to change the / directory to someplace local and now all files will be recovered relative to the new (but temporary) root filesystem.


Bill Hassell, sysadmin
Shannon Petry
Honored Contributor
Solution

Re: Tar Command....

You need to chroot yourself, which requires a few things.
1. cd to a directory which would have enough space to extract the file. Lets call it "/extract" for arguments sake.
2. make a directory under this called "bin" and give it permissions so that you can access it's files.
I.E.
# mkdir /extract/bin
# chmod 755 /extract/bin
3. Next copy "tar" to this directory. This is important because the chrooted environment needs any binaries and libs you will need to access while chrooted.
# cp -p /sbin/tar /extract/bin
NOTE: nothing in /sbin is dynamically linked, so it is safe!
4. chroot and issue the tar command
I.E.
dd if=/dev/rmt/0m | chroot /extract /bin/tar xvf -
NOTE the full path given for tar!!!!!!

This should fix your problems!

Regards,
Shannon
Microsoft. When do you want a virus today?
Abel Berger
Regular Advisor

Re: Tar Command....

Hi Jonethan,

The basic sintaxe to extract file in tar format is :
tar -xvf /dev/rmt/0
When it will be restore depends :
1) your actual position ( directory ).
2) if the tape was write with relative path,
for example, I am in /home and run
"#tar -cvf /dev/rmt/0 . " , you can restore
the files to any filesystem, but if the tape
was the write without relative path, for
example, "#tar -cvf /dev/rmt/0 /home " then
you can only restore the files to the
original filesystem, in this case /home.
3) You can list the tape "tar -tvf /dev/rmt/0"
and to verify how it writed.

I think this help !

Regards,

Abel Berger
Abel Berger
Regular Advisor

Re: Tar Command....

When, I was want say WHERE, OK !

Regards,

Abel Berger