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?
Who is Participating?
slightwv (䄆 Netminder) Commented:
The script in that link appears to have some bad characters in it.

Here is a simpler one:

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

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:
- 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

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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
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,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

AidenAAuthor Commented:
Excellent thanks a lot, worked perfectly.

Thanks for your help once again slightwv!

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.

All Courses

From novice to tech pro — start learning today.