Write batch scripts under Windows to start and reset Oracle database _oracle

Source: Internet
Author: User
Tags goto sqlplus

CMD Start Oracle Database
Create a new bat file, copy the contents in, double-click to start.

@echo off 
net start Oraclexetnslistener 2>nul 
net start oracleservicexe 2>nul 
@oradim-startup-sid XE -starttype Inst > Nul 2>&1 

Oracle Reset Database command
Create a new bat file, copy the following, and then execute.

@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-install Ed or the Oracle is installed to new Oracle home location REM compared to backup time, then user'll be prompted to Ente 
R Flash REM Recovery area location. 
REM rem for database in Noarchivelog mode, the database is restored to last offline REM backup TIME/SCN; REM for database in Archive log mode, the database is restored from the 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 would 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 dat 
Abase 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 erro 
R-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_rmanl 
 Og.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:restorefa Ilederr 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 the 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:p rocess_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%errorle vel% = 0 Set errorstr= RMAN error-see log for details & goto:restorefailederr goto:restoresucess:p Rocess_arc Hivelog @ (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%errorle vel% = 0 Set errorstr= RMAN error-see log for details & Goto:restorefailederr goto:restoresucess:restoresuce 
SS Echo Restore of the database succeeded. 
The 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%. 
The echo Log file is at%restore_rmanlog%. 

 echo ==================== ERROR ============================= Pause Press any key to exit exit Goto:eof

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.