automatically backup oracle database: use task sheduler?

Hi I want to auto back up my oracle database. I ran the command below in the command prompt

exp XX/XXXX file=D:\MANUALTASKS\ManualTasks.dmp log=D:\MANUALTASKS\MANUALTASKS.log tables=MANUAL_TASKS rows=yes indexes=no

imp XX/XXXX file=D:\MANUALTASKS\ManualTasks.dmp full=yes

and it all seemed to work fine. So the next step then is to set this up so that I don't have to do it each day, and also each day to save into a new file so that I can go back to a certain point in time to backup if necessary.

how is it best to do this? I was thinking of perhaps creating some console application and running daily in the task sheduler... but I've never tried to run command line code from visual studio so not even sure if it can be done. How should I go about this?
AidenAAsked:
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.

slightwv (䄆 Netminder) Commented:
You do realize the limitations of using exp/imp as a 'backup'?

The main one is there is no point-in-time recovery.  You can only recover back to the time of the export.

I would just create a .BAT or .CMD file with the Oracle environment setup like PATH and ORACLE_SID.  Then just add that exp command.  You can easily add a DATE piece to the exp command.

check out the BAT date into variable example here:
http://www.tech-recipes.com/rx/956/windows-batch-file-bat-to-get-current-date-in-mmddyyyy-format/
OP_ZaharinCommented:
- i would like to add further on creating a .BAT file. you can create a .BAT file contain your script as follows:

@echo off
exp XX/XXXX file=D:\MANUALTASKS\ManualTasks.dmp log=D:\MANUALTASKS\MANUALTASKS.log tables=MANUAL_TASKS rows=yes indexes=no

- assuming you save it as backupManualTasks.bat. next schedule it to run in Windows Task Scheduler (start menu>accessories>system tools>task scheduler), set it to run daily and the time to run it. then specify the command to run the batch file as follows:

%windir%\system32\cmd.exe C:\backupManualTasks.bat

AidenAAuthor Commented:
Hi thanks,

And if I wanted to specify different names each day for the dmp file based on time... how woud i do that? As in the below (I know that the below won't work because the command is not a string, but is there some way to alter the command like that using variables to achieve the result i'm looking for?)

for example

variable nowDate = NOW.DATE

@echo off
exp XX/XXXX file=D:\MANUALTASKS\ManualTasks & nowDate  & .dmp log=D:\MANUALTASKS\MANUALTASKS.log tables=MANUAL_TASKS rows=yes indexes=no
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

slightwv (䄆 Netminder) Commented:
>>... how woud i do that?

Add a date piece to the filename.  Did you not look at the sample in the link I provided?
AidenAAuthor Commented:
yeah i looked at it, even put it in a .bat file and ran it, with a pause at the end so i could see what happened. but actually it paused when i just put the last line in, but wouldn't when i put everything in. so i couldn't see the output

but lets say that it worked and we have SET date=%mm%%dd%%yyyy%

how do i put the variable 'date' into the command line exactly?

slightwv (䄆 Netminder) Commented:
You don't.  Just build the variables and try something like:

exp XX/XXXX file=D:\MANUALTASKS\ManualTasks_%mm%%dd%%yyyy%.dmp log=D:\MANUALTASKS\MANUALTASKS_%mm%%dd%%yyyy%.log tables=MANUAL_TASKS rows=yes indexes=no

AidenAAuthor Commented:
I don't know, if I try the code below, nothing seems to happen. I think there must be some error which is why it doesn't pause at the end. I can just catch a glimpse of it becuase the console exits and it says '1* was unexpected at this time'

If I remove the top part of the code below then it seems to run as if _%mm%%dd%%yyyy% part below didn't exist. Table exports with no errors into log file.

What is wrong with the below code can you tell me?
FOR /F “TOKENS=1* DELIMS= ” %%A IN (‘DATE/T’) DO SET CDATE=%%B
FOR /F “TOKENS=1,2 eol=/ DELIMS=/ ” %%A IN (‘DATE/T’) DO SET mm=%%B
FOR /F “TOKENS=1,2 DELIMS=/ eol=/” %%A IN (‘echo %CDATE%’) DO SET dd=%%B
FOR /F “TOKENS=2,3 DELIMS=/ ” %%A IN (‘echo %CDATE%’) DO SET yyyy=%%B
SET date=%mm%%dd%%yyyy%

exp XX/XXXX file=D:\MANUALTASKS\ManualTasks_%mm%%dd%%yyyy%.dmp log=D:\MANUALTASKS\MANUALTASKS.log tables=MANUAL_TASKS rows=yes indexes=no

Open in new window

slightwv (䄆 Netminder) Commented:
The script in that link appears to have some bad characters in it.

Here is a simpler one:
http://www.zorbathegeek.com/153/batch-file-to-append-date-to-file-name.html


Your script will look like:
@Echo Off
@For /F "tokens=1,2,3 delims=/ " %%A in ('Date /t') do @( 
Set Day=%%A
Set Month=%%B
Set Year=%%C
Set All=%%C%%B%%A
)

exp XX/XXXX file=D:\MANUALTASKS\ManualTasks_%All%.dmp log=D:\MANUALTASKS\MANUALTASKS.log tables=MANUAL_TASKS rows=yes indexes=no

Open in new window

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
AidenAAuthor Commented:
Excellent thanks a lot, worked perfectly.

Thanks for your help once again slightwv!

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
Oracle Database

From novice to tech pro — start learning today.