Question

Script to backup db

Asked by: crishna1

Experts,

Can someone please provide me a script to backup a Oracle 11g database, using Data Pump.
I would to setup a job for nightly backup.

regards

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-02 at 12:51:48ID24702605
Topics

Oracle 11.x Database

,

Oracle 10.x

Participating Experts
2
Points
500
Comments
32

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. backup oracle db on windows
    I have a backup script that I manually run on a windows 2003 server which I will include below.I manually change the backup directory name everyday before I run the script. But this is a hassle when I have a day of and so. I wanted to schedule this job in windows so that thi...
  2. Veritas Backup Exec v 10 - Verify Fails Nightly Backup
    2-weeks ago my nightly backups started to fail during the "verify" operation. I have two questions.... 1. Is the verify process important - can I recover w/o verification of the checksum; AND 2. How do I fix this issue, so the backup finishes successfully? Deta...
  3. Backup
    Can I use Oracle Exp/Imp as a Backup solution for the oracle 10g database
  4. backup with oracle
    Hi, In oracle, may I know what will be the best backup option available? I heard about cold and hot backup, but I dont understand why the db need to be shutdown in order to do a backup
  5. Stop alert logging of Data Pump jobs.
    Hello, How can I stop the logging of Data Pump jobs entries to the alert log? Example entry in alert log from a Data Pump operation: Thu Jul 31 10:10:37 2008 The value (30) of MAXTRANS parameter ignored. kupprdp: master process DM00 started with pid=20, OS id=5524 ...
  6. Backup job
    i am using Oracle 10gR2 database used OS is Linux. using oracle sussested backup jod daily at specific time. my backup job take much time, size of database is less then 10 gb. how reduce time and how to take faster backup.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: mrjoltcolaPosted on 2009-09-02 at 14:48:14ID: 25245995

Are you aware that a data pump export will not allow you to recover any lost transactions between the last export and the failure?

It is better to use real Oracle backup, like RMAN, and use data pump as supplementary. Here are both options.

-- RMAN backup
rman target /
RMAN> backup database plus archivelog;


Depending on the OS, you need to wrap the data pump in a script to provide a filename based on the date. Also be aware, dumps will go to DATA_PUMP_DIR, so make sure that directory is setup with adequate space. You may have to drop the current one, as it points to a default location that is under the admin directory.

select * from dba_directories;

If you want to change it, do:
drop directory DATA_PUMP_DIR;
create directory DATA_PUMP_DIR as 'C:\dumps';


--Data pump export "backup"
expdp system/admin dumpfile=nightly_ora1.dmpexpdp

 

by: crishna1Posted on 2009-09-03 at 07:17:04ID: 25250900

Thank you for the responce. I do not know much about Oracle and i am not full time into.
Basically what i am looking for is, we have a Oracle database which is not production or anything critical, but it is good to have a back-up.

I read some instructions online and was using the regular export command and it works fine. But the export runs for more than 4-5 hours , after some research online i found that if there are lot of objects with BLOB it takes forever with regular export and data pump is a better alternative and i need a script that does the data pump export nightly.

 

by: MikeOM_DBAPosted on 2009-09-03 at 07:47:11ID: 25251218

Use mrjoltcola's command with parallel option, something like this:

expdp system/admin DUMPFILE=DATA_PUMP_DIR:nightly_expdp%U.dmp PARALLEL=4
                                              
1:

Select allOpen in new window

 

by: MikeOM_DBAPosted on 2009-09-03 at 07:58:21ID: 25251344

PS: Then you create a batch command script and schedule wit WinDoze scheduler:

rem +-- --------------------------
rem +-- nightly_expdp.cmd - Nightly database expdp backup
rem +-- --------------------------
rem + Set the environment (customize to your locations):
SET ORACLE_HOME=C:\Oracle\10.2
SET ORACLE_SID=ORCL
rem +-- Set the path:
SET PATH=%ORACLE_HOME%;%PATH%
expdp system/admin DUMPFILE=DATA_PUMP_DIR:nightly_expdp%U.dmp PARALLEL=4
exit 0
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

Select allOpen in new window

 

by: crishna1Posted on 2009-09-03 at 08:37:20ID: 25251795

Thank you! I will try it and let you know.

 

by: crishna1Posted on 2009-09-03 at 13:29:16ID: 25254623

Hi, This is how my .bat file looks,

SET ORACLE_HOME=C:\Oracle\10.2
SET ORACLE_SID=ABC
rem +-- Set the path:
SET PATH=C:\oracle\product\10.2.0\BIN
expdp system/admin DUMPFILE=DATA_PUMP_DIR:nightly_expdp_ABC.dmp PARALLEL=4
exit 0
---------

I am sure this is not complete, can you please tell me what else am i missing?

 

by: crishna1Posted on 2009-09-03 at 13:30:30ID: 25254632

How do i delete the old file? a del command on the top?

 

by: mrjoltcolaPosted on 2009-09-03 at 13:34:37ID: 25254675

Your script is missing the detail in Mike's solution, which is a %U in the filename, which will generate a new filename. How you delete past dump files is a decision for you, and how much space you have and how you are moving the exports off to external backup media.

 

by: crishna1Posted on 2009-09-03 at 13:51:55ID: 25254814

so basically i change it as shown below? bear with me i am new to this.
expdp system/admin DUMPFILE=DATA_PUMP_DIR:nightly_expdp_%U_ABC.dmp PARALLEL=4

I just want to delete the previous file , what is the command and where do i add it in the script.

 

by: mrjoltcolaPosted on 2009-09-03 at 13:56:21ID: 25254856

It depends on where DATA_PUMP_DIR maps to.

Yes it would be a simple "del" but you need to use the full path. DATA_PUMP_DIR is only known to Oracle as a logical directory. From the host shell, you need to use the full filesystem path.

Prior to the expdp line, you could do:

del C:\dumps\nightly_expdp_*.dmp

 

by: crishna1Posted on 2009-09-03 at 14:27:52ID: 25255137

Thanks, i changed it as follows,

SET ORACLE_HOME=C:\Oracle\10.2
SET ORACLE_SID=QQC2
rem +-- Set the path:
SET PATH=C:\oracle\product\10.2.0\BIN
del C:\export\nightly_dp_exports\nightly_expdp_%U_QQC2.dmp
expdp system/admin DUMPFILE=C:\export\nightly_dp_exports\nightly_expdp_%U_QQC2.dmp PARALLEL=4
exit 0

--------
have dumb question, dont i have to to grant a user read,write privileges on directory data_pump_dir?
where do i specify the user?

 

by: crishna1Posted on 2009-09-03 at 16:01:15ID: 25255760

ignore the user privilege question, that was really a dumb one,  obviously it is SYSTEM.

 

by: mrjoltcolaPosted on 2009-09-03 at 16:08:47ID: 25255809

Yes, for SYSTEM (and other dbas) you don't have to specify DIRECTORY=DATA_PUMP_DIR because that is the default, and a DBA has rights to it. For regular users, however, they need privs, and/or must specify a different directory on the expdp command line.

 

by: MikeOM_DBAPosted on 2009-09-03 at 17:57:55ID: 25256247

Correct your PATH grasshopper:

SET PATH=C:\oracle\product\10.2.0\BIN;%PATH%

 

by: MikeOM_DBAPosted on 2009-09-03 at 18:19:59ID: 25256309

PS: if the PATH is C:\oracle\product\10.2.0\BIN, then ORACLE_HOME is: C:\oracle\product\10.2.0

 

by: crishna1Posted on 2009-09-04 at 08:23:04ID: 25260527

The following is what i have now, it runs ok first time, but only exports system objects, what am i doing wrong. Also, the second time it throws the below shown error, please advice.

rem +-- --------------------------
rem +-- nightly_expdp.cmd - Nightly database expdp backup
rem +-- --------------------------
rem + Set the environment (customize to your locations):
SET ORACLE_HOME=C:\oracle\product\10.2.0
SET ORACLE_SID=ABC
rem +-- Set the path:
SET PATH=C:\oracle\product\10.2.0\BIN
del C:\export\nightly_dp_exports\nightly_expdp_%U_ABC.dmp
del C:\export\nightly_dp_exports\nightly_expdp_%U_ABC2.log
expdp system/tea4two DUMPFILE=DATA_PUMP_DIR:nightly_expdp_%U_ABC.dmp FULL=Y LOGFILE=DATA_PUMP_DIR:nightly_expdp_%U_ABC.log
pause

*********
Error
*******
Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-31641: unable to create dump file "C:\oracle\product/admin/abc/dpdump/nightly_expdp_nightly
_expdp_U_abc.log"
ORA-27038: created file already exists
OSD-04010: <create> option specified, file already exists



 

by: crishna1Posted on 2009-09-04 at 10:07:15ID: 25261492

I figured that FULL=Y has to be specified before the Dumpfile=, i did it and now it is exporting all the schemas. but still have an issue when i run it the second time,

Connected to: Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-31641: unable to create dump file "C:\oracle\product/admin/ABC2/dpdump/nightly_expdp_ABC2U.d
mp"
ORA-27038: created file already exists
OSD-04010: <create> option specified, file already exists

 

by: mrjoltcolaPosted on 2009-09-04 at 10:23:28ID: 25261643

Oops, %U is for multiple files in a single export session, not a complete new filename, as in RMAN (which is why I confused it).

Unless Mike shows otherwise, I don't think data pump supports those format specifiers. I have always generated the filename from the script first, before passing to exp/expdp.

 

by: crishna1Posted on 2009-09-04 at 12:06:03ID: 25262409

well, i took out the %U and used,

expdp system/tea4two FULL=y DUMPFILE=DATA_PUMP_DIR:nightly_expdp_ABC.dmp

But the problem arraises when it run the second time saying that the file already exists.
apparently , the "del" statement before the expdp doesnt work, what now?

 

by: mrjoltcolaPosted on 2009-09-04 at 12:40:03ID: 25262711

It helps to post your script after making changes, so we can see.

 

by: crishna1Posted on 2009-09-04 at 12:42:29ID: 25262730

rem +-- --------------------------
rem + Set the environment (customize to your locations):
SET ORACLE_HOME=C:\oracle\product\10.2.0
SET ORACLE_SID=ABC
rem +-- Set the path:
SET PATH=C:\oracle\product\10.2.0\BIN
del C:\export\nightly_dp_exports\nightly_expdp_ABC.dmp
expdp system/tea4two FULL=y DUMPFILE=DATA_PUMP_DIR:nightly_expdp_ABC.dmp
pause

 

by: mrjoltcolaPosted on 2009-09-04 at 12:50:41ID: 25262799

select * from dba_directories;

Which is DATA_PUMP_DIR mapped to? c:\export or c:\export\nightly_dp_exports?

 

by: mrjoltcolaPosted on 2009-09-04 at 12:51:05ID: 25262802

And the user that is running the script must have OS privileges to delete that file.

 

by: crishna1Posted on 2009-09-04 at 13:06:58ID: 25262917

yes, the user is a admin on the network.

 

by: crishna1Posted on 2009-09-04 at 13:09:32ID: 25262937

oh yeah, i just checked, DATA_PUMP_DIR is mapped to,

DATA_PUMP_DIR C:\oracle\product/admin/ABC/dpdump/

 

by: crishna1Posted on 2009-09-04 at 13:10:17ID: 25262945

i need to map it to C:\export\nightly_dp_exports\, correct?

 

by: mrjoltcolaPosted on 2009-09-04 at 13:11:53ID: 25262962

yep, thats the problem. Drop the directory and re-create.

 

by: crishna1Posted on 2009-09-04 at 13:37:41ID: 25263149

no luck, still the same problem, the old file doesnt get delete, the export fails on the second run :-(

 

by: crishna1Posted on 2009-09-04 at 13:49:10ID: 25263238

i was wrong , it is working on the, i used direct path to delete file instead of the DATA_PUMP_IMP directory, as shown below

del C:\export\nightly_dp_exports\nightly_expdp_ABC.dmp
instead of
del DATA_PUMP_DIR:nightly_expdp_ABC.dmp

 

by: crishna1Posted on 2009-09-04 at 13:50:04ID: 25263242

now i need to get the date on the file ;-).
Thanks for all the help!

 

by: MikeOM_DBAPosted on 2009-09-05 at 06:10:09ID: 25266131

Easy:

rem +-- --------------------------
rem +-- nightly_expdp.cmd - Nightly database expdp backup
rem +-- --------------------------
rem + Set the environment (customize to your locations):
SET ORACLE_HOME=C:\oracle\product\10.2.0\
SET ORACLE_SID=ABC
SET PATH=%ORACLE_HOME%;%PATH%
rem
rem +-- Set the DATA_PUMP_DIR (must be same as directory object in database)
SET BKPDIR=C:\export\nightly_dp_exports
for /F "tokens=2-4 delims=/ " %%d in ('date /t') do SET crdt=%%f%%d%%e
rem
rem +-- Remove file if exists
rem %BKPDIR%\nightly_expdp_ABC%crdt%*
rem
rem +-- Export the data (note the current date %crdt% and %%U)
rem
expdp system/tea4two DUMPFILE=DATA_PUMP_DIR:nightly_expdp_ABC%crdt%_%%U.dmp FULL=Y LOGFILE=DATA_PUMP_DIR:nightly_expdp_ABC%crdt%.log
pause
exit 0
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:

Select allOpen in new window

 

by: MikeOM_DBAPosted on 2009-09-05 at 06:11:26ID: 25266141


Ooops, to remove the file use del (rem won't do it).

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...