Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

i would like to write a shell script to automate the restore of a database

Posted on 2014-10-15
7
469 Views
Last Modified: 2014-10-19
i want to restore an oracle database every day. I so i want to automate the procedure through a shell script and run the shell script to automate it. I also want to generate a log while executing this procedure. I got a restore procedure script in a location. Can somebody help me with developing the shell script for this so i can run the restore script and develop a log file while it is being executed? actually I am new to this
0
Comment
Question by:ram gutha
  • 3
  • 2
7 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40383195
From your previous question on this, you are doing everything with RMAN.

As long as you have the RMAN command file working, the shell script is as simple as setting up the Oracle environment variables (ORACLE_HOME/PATH/etc...) and one line running the RMAN command.

RMAN will create the log file of what it does.
0
 
LVL 23

Accepted Solution

by:
David earned 500 total points
ID: 40383450
UNIX/Linux shells, when run from cron, or manually, typically use a simply redirect to generate a log, for example:

$ORA_SCRIPTS/somerestore.sh > $ORA_LOGS/somerestore_sometimestamp.log 2>&1

Now, using the built-in job scheduler instead of an O'/S scheduler may be worth your consideration, -- but the syntax above should provide your log file.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40383488
>> but the syntax above should provide your log file.

That assumes the script echos output to stdout.  RMAN and a command file has it's own built in logfile and doesn't normally echo to stdout so that syntax likely won't capture anything,

>>Now, using the built-in job scheduler instead of an O'/S scheduler may be worth your consideration,

I assume you are talking about DBMS_SCHEDULER or DBMS_JOB.  I've read where RMAN has PL/SQL API's that should work but I've never used them so I'm not sure what logging aspects they may have.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 34

Expert Comment

by:johnsone
ID: 40384040
The way that I always create scripts like this is to do it manually and write down every single step.  Once you have all the steps down, it is pretty easy to put it all into a script.

One thing to be aware of that I didn't see mentioned yet.  If you run your script through cron, there is no environment set up.  cron does not run any of the login scripts.  If your script works fine interactively, but is failing through cron, missing environment variables is almost always the issue.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40384066
>>One thing to be aware of that I didn't see mentioned yet.

re: http:#a40383195
, the shell script is as simple as setting up the Oracle environment variables (ORACLE_HOME/PATH/etc...)

;)
0
 
LVL 34

Expert Comment

by:johnsone
ID: 40384086
I saw that, but you didn't mention that cron doesn't set the environment.  I was just trying to be clear that it needed to be set in the script if run through cron.  Some people see them set in their environment and don't realize that cron doesn't get those.

Also, the Oracle environment variables may not be the only ones required.  Every shop is different and they may rely on some standard variables that are set at login and don't realize that cron won't see those.  In a lot of places that I have worked, there were environment variables set for log locations and some file locations and if your script is going to rely on those, you need to set them yourself.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question