Windows下编写批处理脚本来启动和重置Oracle数据库
2023-06-13 09:20:05 时间
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 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 The restore log is saved in /DATABASE/OXE_RESTORE.LOG
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
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
我想要获取技术服务或软件
服务范围:MySQL、ORACLE、SQLSERVER、MongoDB、PostgreSQL 、程序问题
服务方式:远程服务、电话支持、现场服务,沟通指定方式服务
技术标签:数据恢复、安装配置、数据迁移、集群容灾、异常处理、其它问题
本站部分文章参考或来源于网络,如有侵权请联系站长。
数据库远程运维 Windows下编写批处理脚本来启动和重置Oracle数据库
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
我想要获取技术服务或软件
服务范围:MySQL、ORACLE、SQLSERVER、MongoDB、PostgreSQL 、程序问题
服务方式:远程服务、电话支持、现场服务,沟通指定方式服务
技术标签:数据恢复、安装配置、数据迁移、集群容灾、异常处理、其它问题
本站部分文章参考或来源于网络,如有侵权请联系站长。
数据库远程运维 Windows下编写批处理脚本来启动和重置Oracle数据库
相关文章
- windows 安装 yarn「建议收藏」
- Oracle数据库格式化输出技巧精选(oracle格式化输出)
- Oracle控制文件的备份策略(oracle控制文件备份)
- Oracle抓取日期:一个实践指南(oracle取日期)
- 查看Oracle数据库名称(查看oracle库名)
- 志故障排查:如何查看Oracle日志?(oracle日)
- 初探Oracle数据库触发器类型(oracle触发器类型)
- Oracle数据库的触发器类型研究(oracle触发器类型)
- 利用Oracle触发器实现数据库自动完成(oracle触发器类型)
- Oracle数据库实现时间分区(oracle创建时间分区)
- Oracle加减函数:简单操作解决大问题(oracle加减函数)
- 利用Oracle轻松实现数据分组合并(oracle分组合并)
- Oracle数据库的主外键技术(oracle主外键)
- Win7快速连接Oracle数据库(win7连接oracle)
- Oracle数据库:如何获取当前时间?(oracle当前时间)
- Oracle依赖关系:数据库设计的重要要素(oracle依赖关系)
- 原生SQL语句实现Oracle数据库Q操作(oracle q 操作)
- Oracle数据库能否免费使用(oracle 免费的吗)
- 利用 Oracle 数据库存储图片的 C 语言实现(c oracle存储图片)
- 激活Oracle企业版破解必备的激活码(oracle企业版激活码)
- Oracle中如何查询非汉字字符(oracle中查非汉字)
- Oracle数据库中的序号列使用技巧(oracle中序号列)
- Oracle 中如何快速赋值变量(oracle中变量赋值)
- Oracle数据库谁获得最高分(oracle中分数最高)
- 类型Oracle中TIME类型的概念与应用(oracle中time)
- 值Oracle中求两个字段差值的方法(oracle两个字段求差)
- 重燃挑战Oracle 11g补考(oracle 11g补考)