Link to home
Create AccountLog in
Avatar of AidenA
AidenA

asked on

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?
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

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

Avatar of AidenA

ASKER

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
>>... how woud i do that?

Add a date piece to the filename.  Did you not look at the sample in the link I provided?
Avatar of AidenA

ASKER

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?

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

Avatar of AidenA

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of AidenA

ASKER

Excellent thanks a lot, worked perfectly.

Thanks for your help once again slightwv!