• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

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
0
LindaC
Asked:
LindaC
  • 4
  • 3
1 Solution
 
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now