Hi all
I need your help to get a high-performance solution.
I am working on a extensive script to automate file restores using the bprestore tool on a Solaris 5.10 server (bash 3.00). I will only paste the needed parts of the script to avoid any confusion.
To use the script the user has to create a file "filelist" within his home directory, including the request number of the file restore on the first line, followed by all filenames which should be restored line by line, first.
The script gets these filenames by a for loop:
fcntr=0
flnms=("")
for flnm in `cat $HOME/filelist`
do
if [ ${fcntr} -eq 0 ]
then
rnmbr=${flnm}
fcntr=$((fcntr+1))
else
flnms=(${flnms[@]} ${flnm})
fi
done
Next step is to get all absolute paths for each file using the bplist tool:
sudo /usr/openv/netbackup/bin/bplist -l -B -R -C ${servername} -b -s ${startdate} -e ${enddate} ${stdsrchpth} | while read filename
do
for file in ${flnms[@]}
do
echo ${filename} | grep "/${file}$" >> ${tmplst}
done
done
or
for file in ${flnms[@]}
do
sudo /usr/openv/netbackup/bin/bplist -l -B -R -C ${servername} -b -s ${startdate} -e ${enddate} ${stdsrchpth} | grep "/${file}$" | while read filename
do
echo ${filename} >> ${tmplst}
done
done
These would be solutions which work as they should... but:
bplist returns more than six million lines which means a very time consuming process.
I tried to use egrep:
sudo /usr/openv/netbackup/bin/bplist -l -B -R -C ${servername} -b -s ${startdate} -e ${enddate} ${stdsrchpth} | egrep "\/file1\$|file2\$|etc.." >> ${tmplst}
Without the \$ part it worked quite fast, but I have to include \$ because the script should not match "file1.data.cdi" if it is searching for "file1.data". I wonder if there is a way to do it like this (including $ as EOL, not as EOF like it happens with the syntax above):
sudo /usr/openv/netbackup/bin/bplist -l -B -R -C ${servername} -b -s ${startdate} -e ${enddate} ${stdsrchpth} | egrep ${flnms[@]} >> ${tmplst}
The script should go through the list of files from bplist only once and directly gets all absolute paths for the files within the array ${flnms[@]} using "\/file1\$|\/file1\$|etc..." as syntax.
Many thanks for your help.