Windows下编写批处理脚本来启动和重置Oracle数据库
cmd启动Oracle数据库
新建一个bat文件,复制内容进去,双击即可启动.
@echooff netstartOracleXETNSListener2>nul netstartOracleServiceXE2>nul @oradim-startup-sidXE-starttypeinst>nul2>&1
Oracle重置数据库命令
新建bat文件,复制以下内容,然后执行。
@echooff REM REMThescriptassumesthatusercanconnectusing"/assysdba" REM REM================= REMRestoreprocedure REM================= REM REMIfInstalledOraclehomeisalsolostandoraclebinarieswere REMre-installedortheOracleisinstalledtoneworaclehomelocation REMcomparedtobackuptime,thenuserwillbepromptedtoenterFlash REMRecoveryArealocation. REM REMFordatabaseinNoArchiveLogmode,databaseisrestoredtolastoffline REMbackuptime/scn; REMFordatabaseinArchivelogmode,databaseisrestoredfromlastbackup REMandacompleterecoveryisattempted.Ifcompleterecoveryfails, REMusercanopenthedatabasewithresetlogsoptionprovidedthefiles REMarenotrecoveryfuzzy. REM REMTherestorelogissavedin?/DATABASE/OXE_RESTORE.LOG REM setlocal set/pinp="Thisoperationwillshutdownandrestorethedatabase.Areyousure[Y/N]?" :checkinp if/i"%inp%"=="Y"goto:confirmedyes if/i"%inp%"=="n"exit :Askagain set/pinp= goto:checkinp :confirmedyes echoRestoreinprogress... echodb_name=xe>%temp%\rman_dummy.ora echosga_target=270M>>%temp%\rman_dummy.ora netstartoracleserviceXe REMStartupdatabaseinnomountmodeusingRMAN... @( echosetechoon^; echostartupnomountpfile=%temp%\rman_dummy.oraforce^; )>%temp%\restore_rman0.dat rmantarget/@%temp%\restore_rman0.dat ifnot%errorlevel%==0setErrorstr=RMANError-couldnotstartupdummyinstance&goto:restorefailederr @( echoconnect/assysdba^; echosetheadoff echosetechooff echosetlinesize515 echovariablevarvarchar2^(512^)^; echoexecute:var:=sys.dbms_backup_restore.normalizefilename^(^'SPFILE2INIT^'^)^; echospool%temp%\spfile2init.log echoselectsys.dbms_backup_restore.normalizefilename^(^'SPFILE2INIT.ORA^'^)spfile2initfromdual^; echoexit^; )>%temp%\spfile2init.sql sqlplus/nolog@%temp%\spfile2init.sql>nul FOR/F%%iin(%temp%\spfile2init.log)dosetSPFILE2INIT=%%i @( echoconnect/assysdba; echosetheadoff echosetechooff echosetlinesize515 echovariablevarvarchar2^(512^)^; echoexecute:var:=sys.dbms_backup_restore.normalizefilename^(^'FRA_LOC^'^)^; echospool%temp%\restore_rmanlog.log echoselectsys.dbms_backup_restore.normalizefilename^(^'OXE_RESTORE.LOG^'^)RESTORE_RMANLOGfromdual^; echoexit^; )>%temp%\restore_rmanlog.sql sqlplus/nolog@%temp%\restore_rmanlog.sql>nul FOR/F%%iin(%temp%\restore_rmanlog.log)dosetRESTORE_RMANLOG=%%i ifnotexist^"%SPFILE2INIT%^"gotoget_rcvarea_loc @( echosetechoon^; echoshutdownimmediate^; echostartupnomountpfile=^"%SPFILE2INIT%^"^; echorestore^(spfilefromautobackup^)^(controlfilefromautobackup^)^; echostartupmountforce^; echoconfigurecontrolfileautobackupoff^; echorestoredatabase^; )>%temp%\restore_rman1.dat rmantarget/@%temp%\restore_rman1.dattrace"%RESTORE_RMANLOG%" ifnot%errorlevel%==0setErrorstr=RMANError-Seelogforerror&goto:restorefailederr gotorestored_files :get_rcvarea_loc set/prcvarea_loc="Entertheflashrecoveryarealocation:" @( echosetechoon^; echorestore^(spfilefromautobackupdb_recovery_file_dest=^'%rcvarea_loc%^'^)^; echostartupnomountforce^; echorestore^(controlfilefromautobackup^)^; echoalterdatabasemount^; echoconfigurecontrolfileautobackupoff^; echorestoredatabase^; )>%temp%\restore_rman1.dat rmantarget/@%temp%\restore_rman1.dattrace"%RESTORE_RMANLOG%" ifnot%errorlevel%==0setErrorstr=RMANError-Seelogforerror&goto:restorefailederr gotorestored_files :restored_files @( echoconnect/assysdba^; echodeclarecursorn1isselectnamefromv$tempfile^; echobegin echoforainn1 echoloop echobegin echosys.dbms_backup_restore.deletefile^(a.name^)^; echoexception echowhenothersthen echonull^; echoend^; echoendloop^; echoend^; echo/ echoexit^; echo/ )>%temp%\deltfile.sql sqlplus/nolog@%temp%\deltfile.sql>nul @( echoconnect/assysdba^; echosetheadoff echosetechooff echospool%temp%\logmode.log echoselectlog_modefromv$database^; echoexit^; )>%temp%\logmode.sql sqlplus/nolog@%temp%\logmode.sql>nul FOR/F%%iin(%temp%\logmode.log)dosetLOGMODE=%%i if"%LOGMODE%"=="NOARCHIVELOG"gotoprocess_noarchivelog if"%LOGMODE%"=="ARCHIVELOG"gotoprocess_archivelog setErrorstr=Unknownlogmode:%LOGMODE% goto:restorefailederr :process_noarchivelog @( echosetechoon^; echoalterdatabaseopenresetlogs; )>%temp%\restore_rman2.dat rmantarget/@%temp%\restore_rman2.dattrace"%RESTORE_RMANLOG%"append ifnot%errorlevel%==0setErrorstr=RMANError-Seelogfordetails&goto:restorefailederr goto:restoresucess :process_archivelog @( echosetechoon^; echorecoverdatabase^; echoalterdatabaseopenresetlogs; )>%temp%\restore_rman2.dat rmantarget/@%temp%\restore_rman2.dattrace"%RESTORE_RMANLOG%"append ifnot%errorlevel%==0setErrorstr=RMANError-Seelogfordetails&goto:restorefailederr goto:restoresucess :restoresucess echoRestoreofthedatabasesucceeded. echoLogfileisat%RESTORE_RMANLOG%. pausePressanykeytoexit exit goto:EOF :restorefailederr echo====================ERROR============================= echoRestoreofthedatabasefailed. echo%Errorstr%. echoLogfileisat%RESTORE_RMANLOG%. echo====================ERROR============================= pausePressanykeytoexit exit goto:EOF