Script help - How to capture each file in a directory in oder to copy to another one

I have the following script.  All oracle files are in directory /tbsprod/ora4/COLDBACKUP/
the lines that begin with copy_file are the locations where the files in the /tbsprod/ora4/COLDBACKUP/   should be after copying them.
What I don't know is how to capture each file from /tbsprod/ora4/COLDBACKUP/  in order to be copied to each directory in the lines that start with the copy_file.

LOG=/home/oracle/dba/logs/cold_Restore_TBSPROD_041510.log
copy_file()
{
 echo Copying $1 >> $LOG
 cp -p /tbsprod/ora4/COLDBACKUP/ $1  >> $LOG
}
copy_file /tbsprod/ora1/TBSPROD/dbf/system_01.dbf
copy_file /tbsprod/ora5/TBSPROD/dbf/undotbs01.dbf
LVL 8
LindaCAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
Hi,

although I cannot fully understand what you're after,
"how to capture each file from  /tbsprod/ora4/COLDBACKUP/ " - that's easy:

find   /tbsprod/ora4/COLDBACKUP -type f | while read file
  do
    echo Do whatever you like with $file inside this loop
  done

Attention - files in subdirectories will be included!

wmp
0
LindaCAuthor Commented:
The thing is that each file has to be in the precise directory mentioned in the lines that are in the lines that stars with the 'copy_file".

The /tbsprod/ora4/COLDBACKUP has the copy of all files to restore the TBSPROD oracle database.  
In order to restore the oracle databse each file in the /tbsprod/ora4/COLDBACKUP, must be copyied back to the place where it had been.  This was capture in the lines that started with "copy_file".
0
woolmilkporcCommented:
OK, my problem is that the parameter for "copy_file" you gave in your Q is "/tbsprod/ora1/TBSPROD/..."  or "/tbsprod/ora5/TBSPROD/..."
How should one know whether the destination is ora1 or ora5 if we only have the filename from "..../COLDBACKUP/..."?

Please run this (it will not do anything real, only echo), to see what I mean:

find   /tbsprod/ora4/COLDBACKUP -type f | while read  file
  do
    echo copy_file $file  /target/directory/$(basename $file)
 done
0
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

woolmilkporcCommented:
... or do you have subdirectories ora1, ora2, ora3 under  /tbsprod/ora4/COLDBACKUP, e.g.  /tbsprod/ora4/COLDBACKUP/ora1/xxx.dbf ?

That would make things possible, like this:

find   /tbsprod/ora4/COLDBACKUP -type f | while read  file
 do
   oradir=$(echo $file |awk -F/ '{print $(NF-1)}')
   echo copy_file $file /tbsprod/$oradir/TBSPROD/dbf/$(basename $file)
done

But only (!) if the first sentence above is true!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LindaCAuthor Commented:
No, I don't have subdirectories in /tbsprod/ora4/COLDBACKUP only the names that are in position #27 starting with /tbsprod......

I think I will do it via oracle.
0
woolmilkporcCommented:
OK,
if there is no hint in the source directory or elsewhere what the target directory of the files-to-copy might be, it would indeed be best, and most probably would mean less effort doing all the backup/restore stuff with Oracle RMAN.
Should you need help with setting up RMAN please ask - we will assist you.
Good luck and have a nice weekend!
wmp
0
LindaCAuthor Commented:
Thank you, the best for you too.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.