me,myself,english and programming..

Automate your oracle import and export using AutoIt

I always believe that I can do almost everything using AutoIt. Well, since I need to do a lot of import and export job manually, I just wondering why not I just automagically do it using AutoIt.

There are a few steps involve in this process :

1. export data from server to my local pc

2. connect to sqlplus and drop user

3. create user and grant permission

4. import back using dump file created in step 1

Now, here how I convert those steps into AutoIt.

Opt("WinTitleMatchMode",2)
$cmdPID = Run("cmd", "", @SW_SHOWNORMAL)
WinWaitActive("cmd.exe")
$hDos = WingetHandle("cmd.exe")
SendKeepActive($hDos)

Send("d:")
Send("{ENTER}")
Send("cd\backup")
Send("{ENTER}")

$filename = @YEAR & @MON & @MDAY & ".dmp"
;First part
$parameter = "arejae/arejae@mydevelopmentserver file=" & $filename
Send('exp.exe ' & $parameter)
Send ("{ENTER}")

;Second part
Send('sqlplus "/as sysdba"')
Send ("{ENTER}")
Send('drop user arejae cascade;')
Send ("{ENTER}")
;assuming no errors..well..just to let you know that assuming is killing...

;3rd part
Send('create user arejae identified by arejae;')
Send ("{ENTER}")
Send('grant DBA to arejae;')
Send ("{ENTER}")

;exit SQLPlus and proceed to import file
Send("exit")
Send("{ENTER}")

;4th part
Send('imp arejae/arejae file='& $filename & ' full=y ')
Send ("{ENTER}")

;done..exit from command prompt
Send("exit")
Send("{ENTER}")

That’s all.. now i can combine all those steps with only one single click or..i can schedule it to run at anytime. :)

Post a Comment