首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

导入导出的回到状态 ERRORLEVEL

2013-01-21 
导入导出的返回状态 ERRORLEVEL在论坛上有人问了这样一个问题,就是imp,exp的返回是什么?这个问题问的比较

导入导出的返回状态 ERRORLEVEL
在论坛上有人问了这样一个问题,就是imp,exp的返回值是什么?这个问题问的比较偏,但是细想一下,在做bat自动导入的时候肯定会用的着,于是查询了一下关于在windows编写导出导入脚本的相关问题,在http://www.dba-oracle.com/t_scripts_windows_export.htm找到了一些头绪,代码如下:

Lets examine Hunter's oracle_export.bat Oracle Windows script.  Note that he builds the exp parfile arguments into a DOS variable called %PARFILE%, just like you can invoke Oracle directly from the DOS prompt (on one line only) : e.g.     

c:> exp=%PARFILE%:

REM +--------------------------------------+
REM | VALIDATE COMMAND-LINE PARAMETERS                                         |
REM +--------------------------------------+

if (%1)==() goto USAGE
if (%2)==() goto USAGE
if (%3)==() goto USAGE


REM +--------------------------------------+
REM | VALIDATE ENVIRONMENT VARIABLES                                           |
REM +--------------------------------------+

REM set ORABACKUP=C:\oracle\orabackup\JEFFDB\export
REM set ORALOG=C:\oracle\custom\oracle\log
REM set ORATMP=C:\oracle\custom\oracle\temp

if (%ORALOG%)==() goto ENV_VARIABLES
if (%ORATMP%)==() goto ENV_VARIABLES
if (%ORABACKUP%)==() goto ENV_VARIABLES


REM +--------------------------------------+
REM | DECLARE ALL GLOBAL VARIABLES.                                            |
REM +--------------------------------------+

set FILENAME=export_backup_online_full_9i
set DB_USERNAME=%1%
set DB_PASSWORD=%2%
set TNS_ALIAS=%3%
set PARFILE=%ORATMP%\%FILENAME%_%TNS_ALIAS%.parfile
set LOGFILE=%ORALOG%\%FILENAME%_%TNS_ALIAS%.log
set DUMPFILE=%ORABACKUP%\exp_full_%TNS_ALIAS%.dmp


REM +--------------------------------------+
REM | REMOVE OLD LOG AND PARAMETER FILE(S).                                    |
REM +--------------------------------------+

del /q %PARFILE%
del /q %LOGFILE%


REM +--------------------------------------+
REM | WRITE EXPORT PARAMETER FILE.                                             |
REM +--------------------------------------+

echo userid=%DB_USERNAME%/%DB_PASSWORD%@%TNS_ALIAS% > %PARFILE%
echo buffer=50000000 >> %PARFILE%
echo file=%DUMPFILE% >> %PARFILE%
echo compress=n >> %PARFILE%
echo grants=y >> %PARFILE%
echo indexes=y >> %PARFILE%
echo direct=no >> %PARFILE%
echo log=%LOGFILE% >> %PARFILE%
echo rows=y >> %PARFILE%
echo consistent=y >> %PARFILE%
echo full=y >> %PARFILE%
REM echo owner=(SCOTT) >> %PARFILE%
REM echo tables=(EMP, DEPT) >> %PARFILE%
echo triggers=y >> %PARFILE%
echo statistics=none >> %PARFILE%
echo constraints=y >> %PARFILE%


REM +--------------------------------------+
REM | MOVE OLD EXPORT (DUMP) FILE.                                             |
REM +--------------------------------------+

del /q %DUMPFILE%.backup
move %DUMPFILE% %DUMPFILE%.backup


REM +--------------------------------------+
REM | PERFORM EXPORT.                                                          |
REM +--------------------------------------+

exp parfile=%PARFILE%


REM +--------------------------------------+
REM | SCAN THE EXPORT LOGFILE FOR ERRORS.                                      |
REM +--------------------------------------+

echo ...
echo Analyzing log file for EXP- errors...
findstr /I /C:"EXP-" %LOGFILE%
if errorlevel 0 if not errorlevel 1 echo EXP- Errors:  %FILENAME% %TNS_ALIAS% %COMPUTERNAME% %DATE% %TIME% %LOGFILE%

echo ...
echo Analyzing log file for ORA- errors...
findstr /I /C:"ORA-" %LOGFILE%
if errorlevel 0 if not errorlevel 1 echo ORA- Errors:  %FILENAME% %TNS_ALIAS% %COMPUTERNAME% %DATE% %TIME% %LOGFILE%

echo ...
echo Analyzing log file for warnings...
findstr /I /C:"Export terminated successfully with warnings" %LOGFILE%
if errorlevel 0 if not errorlevel 1 echo WARNING: %FILENAME% %TNS_ALIAS% %COMPUTERNAME% %DATE% %TIME% %LOGFILE%

echo ...
echo Analyzing log file for errors...
findstr /I /C:"Export terminated unsuccessfully" %LOGFILE%
if errorlevel 0 if not errorlevel 1 echo ERROR: %FILENAME% %TNS_ALIAS% %COMPUTERNAME% %DATE% %TIME% %LOGFILE%


echo ...
echo END OF FILE REPORT
echo Filename      : %FILENAME%
echo Database      : %TNS_ALIAS%
echo Hostname      : %COMPUTERNAME%
echo Date          : %DATE%
echo Time          : %TIME%
echo EXP Log File  : %LOGFILE%

重点在SCAN THE EXPORT LOGFILE FROM ERRORS里面,看到了有这样一些判断IF ERRORLEVEL,这个就是判断是是否正确导出的标志,在MOS里面看到这样一些描述:


A. Successful export/import.
   -------------------------
   Result    : Export terminated successfully without warnings
               Import terminated successfully without warnings
   Exit Code : EX_SUCC
   Exit Level: 0

B. Successful export/import with warnings.
   ---------------------------------------
   Result    : Export terminated successfully with warnings
               Import terminated successfully with warnings
   Exit Code : EX_OKWARN
   Exit Level: 0 (for Unix platforms)
               1 (for Windows platform with Oracle9i, Oracle8i, and below)
               3 (for Windows platform with Oracle10g and higher)

C. Unsuccessful export/import.
   ---------------------------
   Result    : Export terminated unsuccessfully
               Import terminated unsuccessfully
   Exit Code : EX_FAIL
   Exit Level: 1 (for Unix platforms, and for Windows platforms with 
                  Oracle10g and higher)
               3 (for Windows platform with Oracle9i, Oracle8i, and below)

To determine the errorlevel at the commandline after a command ends:

- Unix Bourne/Korn shell:
        echo $?
- Unix C Shell:
        echo $status
- Windows:
        echo %ERRORLEVEL%

意思非常明显,在Oracle11g下

如果 echo %ERRORLEVEL% 为0 则导出的过程是没有警告的。

如果 echo %ERRORLEVEL% 为3 则导出的过程是错误或者有警告的。

热点排行