1834187 Members
2782 Online
110064 Solutions
New Discussion

Tar command

 
kenlo
Advisor

Tar command

Anybady know the tar option to ignore the file origin directory in tape, use "tar option" to restore the any current directory.
For example, tar cvf /dev/rmt/0m /etc/hosts. Want use "tar 'option' /dev/rmt/0m 'current directory'"


Ken
8 REPLIES 8
Steve Steel
Honored Contributor

Re: Tar command

Hi

see 2.3 if your restore whole archive

2.0 tar

2.1 Save a Directory Path With `tar'

If the f option with `tar' is omitted it will take /dev/rmt/0m as the
default tape device file. If your tape drive device file differs, add the
`f' option.

tar cv /directory (absolute path not recommended)

cd /directory; tar cv . (relative path recommended)
or
tar cv ./dir1 ./dir2 ./dir3 ..... (for multiple directories)

2.2 What is written on the `tar' tape?

tar tv
tar tv >/tmp/index

2.3 Restore with `tar'.

cd /directory ; tar xv (relative tar restore)

2.4 `tar' via network.

Write a `tar' tape on a remote computer that owns a DAT/DDS drive.

cd /relative_path
tar cvf - . | remsh name -l user "cat - | dd of=/dev/rmt/0m bs=10k"

Restore a `tar' tape from a remote computer that owns a DAT/DDS drive.
cd /relative_path
remsh name -l user dd if=/dev/rmt/0m bs=10k | tar xvf -

2.5 Good to know about tar!

`tar' is an easy command and can be used as interchange format. These are
the only advantages.

I would like to advise you not to use `tar' to back-up a couple of gigabytes,
because `tar' does not support `regular expressions'. Selected file
retrieval is only possible by this command:

tar xv `tar t | grep "^user/drawings*"


To backup and recover to another directory with great options you need fbackup/frecover.

Regards

Steve Steel

Quote of the moment
-------------------
"We are drowning in information but starved for knowledge."
-- John Naisbitt
If you want truly to understand something, try to change it. (Kurt Lewin)
Chris Wilshaw
Honored Contributor

Re: Tar command

Tar isn't very sophisticated in this respect

The best you can hope for is to create the archive using

cd /etc
tar cvf /dev/rmt/0m hosts

This will then create the archive with no leading directories, so that you can then use

cd /your_new_dir
tar xvf /dev/rmt/0m hosts
Stefan Farrelly
Honored Contributor

Re: Tar command

HP's tar cant do it, but the gun version can. You can download the gnu version of tar from;

http://hpux.cs.utah.edu/
Im from Palmerston North, New Zealand, but somehow ended up in London...
RAC_1
Honored Contributor

Re: Tar command

In order to avoid tar backups with absolute path names I always use
tar -cvf /dev/rmt/rmt/0m ./etc/*

But in case you do take it absolute path names you can restore wiht pax.

cd /your_dir
pax -rv -s '/^\///' < /dev/rmt/0m
There is no substitute to HARDWORK
Steve Steel
Honored Contributor

Re: Tar command

Hi


Worst case scenario is a chroot

In the future use fbackup since tar is a simple soul.

Restore a complete directory

/etc/frecover -xi/directory
/etc/frecover -x -i/directory1 -i/directory2

When restoring a directory, `frecover' will not overwrite an existing
file, except if the -o option is used.

It may be nice to recover relative somewhere in a directory like /tmp/local.
To restore relative, you must go first to the directory with cd, and then
use the X or F option.

cd /tmp/local; /etc/frecover -xvXi /directory
(with directory tree path )
cd /tmp/local; /etc/frecover -xvFi /directory
(without path, only files names)


Regards

Steve Steel

Quote of the moment
-------------------
"We are drowning in information but starved for knowledge."
-- John Naisbitt
If you want truly to understand something, try to change it. (Kurt Lewin)
harry d brown jr
Honored Contributor

Re: Tar command

As of this moment, Anil is the only one that has it right. You MUST use pax to restore a ABSOLUTE PATH backup to a ALTERNATE (RELATIVE) directory, though I find this syntax a little easier:

cd to desired directory
pax -r -s ',^/,,' -f file.tar

(no need for back slashes)

live free or die
harry
Live Free or Die
RAC_1
Honored Contributor

Re: Tar command

Harry I was going to put that syntax. I read man page for pax many times but did not understand anything, particularly -s options syntax

It is easy to remember
/^\///

four forward slashes and one backward slash
There is no substitute to HARDWORK
James R. Ferguson
Acclaimed Contributor

Re: Tar command

Hi:

Harry's use of the comma (",") as a delimiter makes the *substitution* ('-s') 'pax' syntax easier to read than using a "/" delimiter and having to escape its dual meaning as part of a filename or directory and as a delimiter. *Any* character can be used as a delimiter. Note that the syntax mirrors that of 'sed'.

Regards!

...JRF...