Windows下編寫批處理腳本來(lái)啟動(dòng)和重置Oracle數(shù)據(jù)庫(kù)
cmd啟動(dòng)Oracle數(shù)據(jù)庫(kù)
新建一個(gè)bat文件,復(fù)制內(nèi)容進(jìn)去,雙擊即可啟動(dòng).
@echo off net start OracleXETNSListener 2>nul net start OracleServiceXE 2>nul @oradim -startup -sid XE -starttype inst > nul 2>&1
Oracle重置數(shù)據(jù)庫(kù)命令
新建bat文件,復(fù)制以下內(nèi)容,然后執(zhí)行。
@echo off REM REM The script assumes that user can connect using "/ as sysdba" REM REM ================= REM Restore procedure REM ================= REM REM If Installed Oracle home is also lost and oracle binaries were REM re-installed or the Oracle is installed to new oracle home location REM compared to backup time, then user will be prompted to enter Flash REM Recovery Area location. REM REM For database in NoArchiveLog mode, database is restored to last offline REM backup time/scn; REM For database in Archive log mode, database is restored from last backup REM and a complete recovery is attempted. If complete recovery fails, REM user can open the database with resetlogs option provided the files REM are not recovery fuzzy. REM REM The restore log is saved in ?/DATABASE/OXE_RESTORE.LOG REM setlocal set /p inp="This operation will shut down and restore the database. Are you sure [Y/N]?" :checkinp if /i "%inp%" == "Y" goto :confirmedyes if /i "%inp%" == "n" exit :Askagain set /p inp= goto :checkinp :confirmedyes echo Restore in progress... echo db_name=xe >%temp%\rman_dummy.ora echo sga_target=270M >>%temp%\rman_dummy.ora net start oracleserviceXe REM Startup database in nomount mode using RMAN... @( echo set echo on^; echo startup nomount pfile=%temp%\rman_dummy.ora force^; ) > %temp%\restore_rman0.dat rman target / @%temp%\restore_rman0.dat if not %errorlevel% == 0 set Errorstr= RMAN Error - could not startup dummy instance & goto :restorefailederr @( echo connect / as sysdba^; echo set head off echo set echo off echo set linesize 515 echo variable var varchar2^(512^)^; echo execute :var := sys.dbms_backup_restore.normalizefilename^(^'SPFILE2INIT^'^)^; echo spool %temp%\spfile2init.log echo select sys.dbms_backup_restore.normalizefilename^(^'SPFILE2INIT.ORA^'^) spfile2init from dual^; echo exit^; ) > %temp%\spfile2init.sql sqlplus /nolog @%temp%\spfile2init.sql >nul FOR /F %%i in (%temp%\spfile2init.log) do set SPFILE2INIT=%%i @( echo connect / as sysdba; echo set head off echo set echo off echo set linesize 515 echo variable var varchar2^(512^)^; echo execute :var := sys.dbms_backup_restore.normalizefilename^(^'FRA_LOC^'^)^; echo spool %temp%\restore_rmanlog.log echo select sys.dbms_backup_restore.normalizefilename^(^'OXE_RESTORE.LOG^'^) RESTORE_RMANLOG from dual^; echo exit^; ) > %temp%\restore_rmanlog.sql sqlplus /nolog @%temp%\restore_rmanlog.sql >nul FOR /F %%i in (%temp%\restore_rmanlog.log) do set RESTORE_RMANLOG=%%i if not exist ^"%SPFILE2INIT%^" goto get_rcvarea_loc @( echo set echo on^; echo shutdown immediate^; echo startup nomount pfile=^"%SPFILE2INIT%^"^; echo restore ^(spfile from autobackup^) ^(controlfile from autobackup^)^; echo startup mount force^; echo configure controlfile autobackup off^; echo restore database^; ) > %temp%\restore_rman1.dat rman target / @%temp%\restore_rman1.dat trace "%RESTORE_RMANLOG%" if not %errorlevel% == 0 set Errorstr= RMAN Error - See log for error & goto :restorefailederr goto restored_files :get_rcvarea_loc set /p rcvarea_loc="Enter the flash recovery area location:" @( echo set echo on^; echo restore ^(spfile from autobackup db_recovery_file_dest=^'%rcvarea_loc%^'^)^; echo startup nomount force^; echo restore ^(controlfile from autobackup^)^; echo alter database mount^; echo configure controlfile autobackup off^; echo restore database^; ) > %temp%\restore_rman1.dat rman target / @%temp%\restore_rman1.dat trace "%RESTORE_RMANLOG%" if not %errorlevel% == 0 set Errorstr= RMAN Error - See log for error & goto :restorefailederr goto restored_files :restored_files @( echo connect / as sysdba^; echo declare cursor n1 is select name from v$tempfile^; echo begin echo for a in n1 echo loop echo begin echo sys.dbms_backup_restore.deletefile^(a.name^)^; echo exception echo when others then echo null^; echo end^; echo end loop^; echo end^; echo / echo exit^; echo / ) > %temp%\deltfile.sql sqlplus /nolog @%temp%\deltfile.sql >nul @( echo connect / as sysdba^; echo set head off echo set echo off echo spool %temp%\logmode.log echo select log_mode from v$database^; echo exit^; ) > %temp%\logmode.sql sqlplus /nolog @%temp%\logmode.sql >nul FOR /F %%i in (%temp%\logmode.log) do set LOGMODE=%%i if "%LOGMODE%" == "NOARCHIVELOG" goto process_noarchivelog if "%LOGMODE%" == "ARCHIVELOG" goto process_archivelog set Errorstr= Unknown log mode : %LOGMODE% goto :restorefailederr :process_noarchivelog @( echo set echo on^; echo alter database open resetlogs; ) > %temp%\restore_rman2.dat rman target / @%temp%\restore_rman2.dat trace "%RESTORE_RMANLOG%" append if not %errorlevel% == 0 set Errorstr= RMAN Error - See log for details & goto :restorefailederr goto :restoresucess :process_archivelog @( echo set echo on^; echo recover database^; echo alter database open resetlogs; ) > %temp%\restore_rman2.dat rman target / @%temp%\restore_rman2.dat trace "%RESTORE_RMANLOG%" append if not %errorlevel% == 0 set Errorstr= RMAN Error - See log for details & goto :restorefailederr goto :restoresucess :restoresucess echo Restore of the database succeeded. echo Log file is at %RESTORE_RMANLOG%. pause Press any key to exit exit goto :EOF :restorefailederr echo ==================== ERROR ============================= echo Restore of the database failed. echo %Errorstr%. echo Log file is at %RESTORE_RMANLOG%. echo ==================== ERROR ============================= pause Press any key to exit exit goto :EOF
相關(guān)文章
oracle 實(shí)際值超過(guò)數(shù)據(jù)庫(kù)某個(gè)字段指定長(zhǎng)度報(bào)錯(cuò)解決
本節(jié)主要介紹了oracle 實(shí)際值超過(guò)數(shù)據(jù)庫(kù)某個(gè)字段指定長(zhǎng)度報(bào)錯(cuò)解決方法,需要的朋友可以參考下2014-07-07
Oracle 數(shù)據(jù)庫(kù)忘記sys與system管理員密碼重置操作方法
這篇文章主要介紹了Oracle 數(shù)據(jù)庫(kù)忘記sys與system管理員密碼重置操作,需要的朋友可以參考下2017-06-06
Oracle RAC環(huán)境下的阻塞(blocking blocked)介紹和實(shí)例演示
這篇文章主要介紹了Oracle RAC環(huán)境下的阻塞(blocking blocked)介紹和實(shí)例演示本文提供了2個(gè)查詢腳本,并給出實(shí)例演示那些session為阻塞者,哪些為被阻塞者,需要的朋友可以參考下2014-09-09
Oracle監(jiān)聽(tīng)器被優(yōu)化大師掛掉后的完美解決方法
這篇文章主要介紹了Oracle監(jiān)聽(tīng)器被優(yōu)化大師掛掉后的完美解決方法,需要的朋友可以參考下2017-08-08
在Oracle關(guān)閉情況下如何修改spfile的參數(shù)
大家都知道在Oracle中pfile參數(shù)是可以手動(dòng)更改的,但是spfile是二進(jìn)制文件所以不可以手動(dòng)更改,但我最近遇到了一個(gè)問(wèn)題,修改參數(shù)錯(cuò)誤,導(dǎo)致Oracle啟動(dòng)不了,一定要修改spfile該怎么辦呢?下面通過(guò)這篇文章來(lái)一起看看吧。2016-12-12
oracle數(shù)據(jù)庫(kù)中查看系統(tǒng)存儲(chǔ)過(guò)程的方法
這篇文章主要介紹了oracle數(shù)據(jù)庫(kù)中查看系統(tǒng)存儲(chǔ)過(guò)程的方法,需要的朋友可以參考下2014-06-06

