Operating System - HP-UX
1831435 Members
3331 Online
110025 Solutions
New Discussion

gtar & pattern matching script problem

 
Chern Jian Leaw
Regular Advisor

gtar & pattern matching script problem

HI,

I know that this problem is very similar in nature to the thread on "gtar-extracting tape contents." But I'd like some help with some scripts provided this thread.

I have 7 tapes contains archived filesystems of the form:
/bak/fs37/opt_regression
/bak/fs37/fourier_calc
/bak/fs20/run_script
(list continues ...)

Every archived filesystems have the /bak as the prefix in the filesystem name.

I would like to have these filesystems extracted from the tape and restored as:
/fs37/opt_regression
/fs37/fourier_calc
/fs20/run_script

NOT as
/bak/fs37/opt_regression
/bak/fs37/fourier_calc
/bak/fs20/run_script


I have a script written by Ceesjan Van Hatum which should ignore the /bak prefix during restore, but somehow it DID NOT:

#cat ceesjan.sh
#!/bin/sh
for i in `gtar -tvf /dev/rmt1`
do
echo "Retrieving $i"
gtar -xvf /dev/rmt $i
mv /bak/$i /$i
done

Could someone please show me how I should do a pattern match to extract only the of suffixes /bak from the tapes?
e.g:
/bak/fs37/opt_regression to be extracted and restored as /fs37/opt_regression

Or are there any other alternatives to this problem?

Could someone please help?

Thanks in advance.
3 REPLIES 3
KapilRaj
Honored Contributor

Re: gtar & pattern matching script problem

does it give an error message ?. does "/fs37/opt_regression" already exist in the box ?. If yes move it to another name. then run the same script. that should work .

A best solution to the problem is, to avoid taking backups with absolute path. When you take backup take it with a relative path i mean , if u need to backup /fs37/opt_regression directory take it like "./fs37/opt_regression" so that u can directly restore it any where.

do give a try in the test box. then go to prod. box

kaps





Nothing is impossible
Chern Jian Leaw
Regular Advisor

Re: gtar & pattern matching script problem

Kapil,

Unfortunately I can't change the way it has been archived into the tapes. This is because these tapes were shipped from overseas.

Any other ideas?

Thanks.
Deepak Extross
Honored Contributor

Re: gtar & pattern matching script problem

You can get the suffix of /bak like this:
cut -d\/ -f3-

for example,
echo /bak/fs37/fourier_calc | cut -d\/ -f3-
will give you
fs37/fourier_calc

Assuming you have a valid & usable /bak on your system, the following script should extract one directory at a time into /bak and then move it to $extract_dir. (Not tested, you may have to make some small changes.)

#!/bin/sh
extract_dir=
cd /bak
for i in `gtar -tvf /dev/rmt1`
do
echo "Retrieving $i"
gtar -xvf /dev/rmt $i
j=`echo $i | cut -d\/ -f3-`
mv $j ${extract_dir}/${j}
done