ERRORLEVEL is not %ERRORLEVEL%

本文解析了CMD命令解释器中ERRORLEVEL的概念及其与名为ERRORLEVEL的环境变量之间的区别。ERRORLEVEL用于记录最近运行程序的退出代码,可通过IF ERRORLEVEL命令进行测试。而设置的ERRORLEVEL环境变量不会影响命令解释器内部的ERRORLEVEL状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 转帖自http://blogs.msdn.com/oldnewthing/archive/2008/09/26/8965755.aspx

 

ERRORLEVEL is not %ERRORLEVEL%

The command interpreter cmd.exe has a concept known as the error level, which is the exit code of the program most recently run. You can test the error level with the IF ERRORLEVEL command:

IF ERRORLEVEL 1 ECHO error level is 1 or more

<sidebar>
The IF ERRORLEVEL n test succeeds if the error level is n or more. This was presumably because there were programs that expressed different degrees of failure with higher and higher exit codes. For example, the diff program has three exit codes: 0 means the files are the same; 1 means the files are different; 2 means that something terrible happened. There are also programs that use an exit code of zero to mean success and anything else to mean failure.
</sidebar>

In addition to this internal state, you can, if you wish, create an environment variable with the name ERRORLEVEL, in the same way that you can create an environment variable called FRED. But, as with FRED, that variable won't have any effect on the error level.

rem this next command sets the error level to zero
CMD /C EXIT 0
set ERRORLEVEL=1
if ERRORLEVEL 1 echo Does this print?

The message is not printed because the ERRORLEVEL environment variable has no effect on the error level. It's just a variable whose name happens to coincide with a command processor concept.

set BANKBALANCE=$1,000,000.00

"Hey, when I tried to withdraw the money, I got an insufficient funds error. What am I doing wrong?"

Now, it does happen to be the case that if command extensions are enabled and you say %ERRORLEVEL%, then the command processor first looks for an environment variable called ERRORLEVEL, and if it can't find one, then it replaces %ERRORLEVEL% with the current value of the internal error level value. It's a fallback step, in the same way that your neighbor is a fallback delivery location if you aren't home. If you file a change-of-address form for yourself, that doesn't affect packages sent to your neighbor.

The same behavior can be seen with %CD%: If you did not explicitly set an environment variable called CD, then %CD% expands to the command processor's current directory. But you can't change directories by saying set CD=C:/Windows.

I can think of a few reasons why this feature may have been added.

  • So you can include the error level in a log file:
    ECHO error level is %ERRORLEVEL%>logfile
  • So you can perform other types of tests against the error level, for example, to perform an equality test:
    IF %ERRORLEVEL% EQU 1 echo Different!

But I'm digressing. My point for today is that the error level is not the same as the ERRORLEVEL environment variable.

解释下面这段cmd文件的作用:CLS REM The following is required in all INSTALL.CMD files if exist c:\system.sav\util\SetVariables.cmd Call c:\system.sav\util\SetVariables.cmd set version=1.05 Set block=%~dp0 set errcodeinstallinstallinstallinstallinstallinstallinstall=0 CD /D "%block%" set Log_Folder=%~d0\programdata\HP\logs if not exist "%Log_Folder%" md "%Log_Folder%" set Install_Log=%Log_Folder%\HotkeyInstall.log REM Remove the REM from the next line if your component does not support Silent Install (Application Recovery) REM Erase /F /Q *.CVA REM Add the command-line to have your component to be installed properly Pushd src if exist "%~dp0src\Uninstall.cmd" ( call "%~dp0src\Uninstall.cmd" ) if %errorlevel% NEQ 0 ( echo. >> "%Install_log%" echo *exit /b %errcodeinstall% >> "%Install_log%" echo. >> "%Install_log%" echo ^<^< %~f0 >> "%Install_log%" echo ^<^< %date% %time% >> "%Install_log%" echo. >> "%Install_log%" goto :END ) if exist "%~dp0src\InstallFusion.cmd" ( call "%~dp0src\InstallFusion.cmd" ) if %errorlevel% NEQ 0 ( echo. >> "%Install_log%" echo *exit /b %errcodefusion% >> "%Install_log%" echo. >> "%Install_log%" echo ^<^< %~f0 >> "%Install_log%" echo ^<^< %date% %time% >> "%Install_log%" echo. >> "%Install_log%" goto :END ) if exist "%~dp0src\InstallDriver.cmd" ( call "%~dp0src\InstallDriver.cmd" ) if %errorlevel% NEQ 0 ( echo. >> "%Install_log%" echo *exit /b %errcodedriver% >> "%Install_log%" echo. >> "%Install_log%" echo ^<^< %~f0 >> "%Install_log%" echo ^<^< %date% %time% >> "%Install_log%" echo. >> "%Install_log%"goto :END ) if exist "%~dp0src\InstallApp.cmd" ( call "%~dp0src\InstallApp.cmd" ) if %errorlevel% NEQ 0 ( echo. >> "%Install_log%" echo *exit /b %errcodeapp% >> "%Install_log%" echo. >> "%Install_log%" echo ^<^< %~f0 >> "%Install_log%" echo ^<^< %date% %time% >> "%Install_log%" echo. >> "%Install_log%" goto :END ) :END Popd REM Erase failure flag file when install succeeded. Most applications return zero to indicate success. ECHO %ERRORLEVEL% >> FAILURE.FLG IF %ERRORLEVEL% EQU 0 ERASE /F /Q FAILURE.FLG IF %ERRORLEVEL% EQU 3010 ERASE /F /Q FAILURE.FLG echo %date% %time% "Fusion=" %errcodefusion% >> %install_log% echo %date% %time% "Driver=" %errcodedriver% >> %install_log% echo %date% %time% "App=" %errcodeapp% >> %install_log% EXIT /B %ERRORLEVEL%
07-20
解释以下脚本:@echo off&setlocal enabledelayedexpansion :: 日志路径 set var_date=%date:~0,10% set var_date=%var_date:-=% set log_path=%temp%\ibdata%var_date%.log echo ******* start process ******** echo. echo %time% start process >> %log_path% echo %log_path% pause :: 脚本的存放位置固定为 D:\naura echo %cd% pause if %cd% NEQ D:\naura ( echo %time% work path is %cd% >> %log_path% echo 请将脚本文件及ibdata1文件放在 D:\naura 目录下 echo. pause exit 0 ) :: 检查ibdata1 文件是否存在 if not exist ibdata1 ( echo ibdata1 文件不存在,请检查脚本文件所在目录 echo. pause exit 0 ) :: 检查ibdata1 文件是否存在 if not exist tables.txt ( echo tables.txt 文件不存在,请检查脚本文件所在目录 echo. pause exit 0 ) :: 校验 ibdata1 的大小是否符合预期 for /f %%i in ('dir /b ibdata1') do ( echo %time% lastest ibdata1 file size is %%~zi >> %log_path% if %%~zi NEQ 10485760 ( echo ibdata1 文件大小不对,请核对脚本目录下 ibdata1 文件 echo. pause exit 0 ) ) set excute_h=1 set excute_m=1 set excute_s=1 :: 是否需要手动干预的标志 set handwork=0 :: 检查数据库是否启动 同时检查是否有数据库操作权限 tasklist|find /i "mysqld.exe" >> %log_path% if %errorlevel% NEQ 0 ( echo %time% mysql is not running and started to start >> %log_path% net start mysql >> %log_path% 2>&1 if !errorlevel! NEQ 0 ( echo %time% failed to start mysql echo mysql 启动失败,请手动启动mysql服务之后,再执行脚本 echo. pause exit 0 ) ) else ( echo %time% verify that we have execute net permission >> %log_path% net help >> %log_path% 2>&1 if !errorlevel! NEQ 0 ( echo %time% we don't have authority >> %log_path% echo 由于权限问题,清理过程需要您手动干预,请不要离开机台,注意脚本运行!! echo. pause echo. set handwork=1 ) ) echo %time% begin excute clean mysql data echo. :: 定义变量,方便修改 set mysqlServer=localhost set mysqlUser=root set mysqlPassword=8888 set database_fa300=fa300 set database_scope=scope set curObj.table=0 set curObj.field=0 set export_ingnore_table=%database_scope% set dataSavePath=naura_scope set tryCount=0 :: 获取所有数据记录表,表中数据需要根据时间备份 set tableCounts=0 set obj=0 for /f "delims=: tokens=1-2" %%i in (tables.txt) do ( for /f "skip=1" %%a in ('mysql -h%mysqlServer% -u%mysqlUser% -p%mysqlPassword% -e "select count(0) from information_schema.tables where table_name='%%i' and table_schema='%database_scope%'"') do ( if %%a EQU 1 ( set obj[!tableCounts!].table=%%i set obj[!tableCounts!].field=%%j set /a tableCounts=!tableCounts!+1 ) ) ) :: 脚本执行过程中产生的临时参数保存路径 set process_param=%temp%\ibdata_param.log :: 临时数据保存的磁盘 set param_volume=0 :: 脚本执行到第几步 set param_step=0 :: 参数文件产生日期 set param_date=0 :: 备份天数 set param_day=0 :: ibdata 文件路径 set param_ibdataPath=0; :: 导出或导入数组 obj 的下标 set param_tableIndex=0; set begin_time=%time% if not exist %process_param% goto:step0 echo %time% %process_param% file exist >> %log_path% echo ----------------------- >> %log_path% type %process_param% >> %log_path% echo ----------------------- >> %log_path% for /f "delims== tokens=1-2" %%i in (%process_param%) do ( if %%i EQU param_date ( set param_date=%%j ) ) echo %time% param_date: %param_date% >> %log_path% :: 判断已经存在的参数,是否为同一天,默认同一天的可以继续使用 if %date:~0,10% NEQ %param_date% goto:step0 :: 获取所有的参数 for /f "delims== tokens=1-2" %%i in (%process_param%) do ( if %%i EQU volume ( set param_volume=%%j ) else if %%i EQU step ( set param_step=%%j ) else if %%i EQU day ( set param_day=%%j ) else if %%i EQU ibdataPath ( set param_ibdataPath=%%j ) else ( set param_tableIndex=%%j ) ) echo %time% param: %param_volume% %param_step% %param_day% %param_ibdataPath% %param_tableIndex%>> %log_path% if not exist "%param_ibdataPath%" goto:step0 goto:step%param_step% :: 环境准备 :: 1 获取临时数据存储位置 :: 2 获取 mysql data 的位置 :: 3 判断临时数据存储空间是否满足 :: 4 估算脚本运行时间 :step0 echo %time% begin excute step0 >> %log_path% del /Q/F %process_param% >> %log_path% 2>&1 :: 自动获取可用空间最大的非系统盘, 如果存在 E 盘,则直接默认 E 盘 set param_volume=0 set volume_freespace=0 for /f "Skip=2 tokens=1-2" %%i in ('Wmic LogicalDisk where "DriveType=3" Get FreeSpace^,Name') do ( echo %time% %%j %%i >> %log_path% set tempSize=%%i set /a tempSize=!tempSize:~0,-6! / 1074 > nul 2>&1 if %%j EQU E: ( set param_volume=%%j set /a volume_freespace=!tempSize! goto:endVolume ) if !tempSize! GTR !volume_freespace! ( set param_volume=%%j set /a volume_freespace=!tempSize! ) ) :endVolume echo %time% the path to save the temp data is %param_volume%, freespce is %volume_freespace%GB >> %log_path% if not exist %param_volume%\%dataSavePath% md %param_volume%\%dataSavePath% :: 获取 ibdata1 文件路径 echo %time% show variables datadir >> %log_path% mysql -h %mysqlServer% -u %mysqlUser% -p%mysqlPassword% -e "show variables like 'datadir'" > %param_volume%\%dataSavePath%\data.txt 2>>%log_path% type %param_volume%\%dataSavePath%\data.txt >> %log_path% for /f "delims= tokens=1" %%i in (%param_volume%\%dataSavePath%\data.txt) do ( echo %%i | findstr "Value" >nul && echo. >nul || set param_ibdataPath=%%i ) set param_ibdataPath=%param_ibdataPath:~8%ibdata1 set param_ibdataPath=%param_ibdataPath:\\=\% if not exist "%param_ibdataPath%" ( mysql -h %mysqlServer% -u %mysqlUser% -p%mysqlPassword% -e "show variables like 'innodb_data_home_dir'" > %param_volume%\%dataSavePath%\data.txt 2>>%log_path% type %param_volume%\%dataSavePath%\data.txt >> %log_path% for /f "delims= tokens=1" %%i in (%param_volume%\%dataSavePath%\data.txt) do ( echo %%i | findstr "Value" >nul && echo. >nul || set param_ibdataPath=%%i ) set param_ibdataPath=!param_ibdataPath:~21!ibdata1 set param_ibdataPath=!param_ibdataPath:\\=\! ) echo. echo !param_ibdataPath! echo ibdata1 file path !param_ibdataPath! >> %log_path% echo. if not exist "%param_ibdataPath%" ( echo 没有找到 ibdata 文件,请联系软件工程师!!!! echo. pause exit ) :: 获取客户端 ibdata file size set oldIbdataSize=0 for /f "tokens=3" %%i in ('dir "%param_ibdataPath%"^|find /i "1 个文件"') do ( set oldIbdataSize=%%i ) set oldIbdataSize=%oldIbdataSize:,=% echo %time% old ibdata file size is %oldIbdataSize% >> %log_path% :: 判断临时数据存储位置的空间是否够用 set /a oldIbdataSize=%oldIbdataSize:~0,-6% / 1074 echo %time% old ibdata file size is %oldIbdataSize%GB >> %log_path% set /a oldIbdataSize=%oldIbdataSize%+10 if %volume_freespace% LSS %oldIbdataSize% ( echo %param_volume% freespce is too small >> %log_path% echo %param_volume% 剩余空间太小,至少需要 %oldIbdataSize%GB 空间,请手动清理后再次运行脚本 echo. pause exit 0 ) set /a oldIbdataSize=%oldIbdataSize%*3 echo 整个清理过程大约需要 %oldIbdataSize% min echo. set param_step=1 call:fun_save_param echo %time% end excute step0 >> %log_path% :: 输入所需备份多久的数据,主要备份腔室表和 transfer表 :step1 echo %time% begin excute step1 >> %log_path% set /p param_day=请输入需要备份数据的天数(最大为120): echo. echo %param_day%|findstr "^[0-9]*$">nul if %errorlevel% NEQ 0 ( echo 请输入整数 echo. goto:step1 ) if %param_day% GTR 120 ( echo 备份时间超过 120 ,请重新输入 echo. goto:step1 ) set param_step=2 call:fun_save_param echo %time% end excute step1 >> %log_path% :: 备份客户端 ibdata :step2 echo %time% begin excute step2 >> %log_path% set tryCount=0 :backup set /a tryCount=%tryCount% + 1 if %tryCount% EQU 4 ( echo !!!!!备份 %param_ibdataPath% 失败,请手动备份至其他磁盘后,再继续执行脚本!!!!! echo. pause set param_step=3 call:fun_save_param exit 0 ) echo %time% begin backup ibdata1 echo %time% begin backup ibdata1 >> %log_path% copy /Y/V/Z "%param_ibdataPath%" %param_volume%\%dataSavePath%\ibdata1 if %errorlevel% NEQ 0 goto:backup echo %time% end backup ibdata1 echo. set param_step=3 call:fun_save_param echo %time% end backup ibdata1 >> %log_path% echo %time% end excute step2 >> %log_path% :: 清理数据库中备份表,及备份表中数据 :step3 echo %time% begin excute step3 >> %log_path% echo %time% begin clean history table for /f "skip=1" %%a in ('mysql -h%mysqlServer% -u%mysqlUser% -p%mysqlPassword% -e "select count(0) from information_schema.tables where table_name='backuphistory' and table_schema='%database_scope%'"') do ( if %%a EQU 1 ( goto:history ) else ( goto:skiphistory ) ) :history for /f "skip=1 tokens=1" %%i in ('mysql -h%mysqlServer% -u%mysqlUser% -p%mysqlPassword% --database %database_scope% -e "select backupname from backuphistory where backuptime < date_sub(curdate(), interval %param_day% day)"') do ( echo %time% delete history table %%i echo %time% delete history table %%i >> %log_path% mysql -h%mysqlServer% -u%mysqlUser% -p%mysqlPassword% --database %database_scope% -e "delete from backuphistory where backupname='%%i'" 2>>%log_path% mysql -h%mysqlServer% -u%mysqlUser% -p%mysqlPassword% --database %database_scope% -e "drop table %%i" 2>>%log_path% ) :skiphistory echo %time% end clean history table echo. set param_step=4 call:fun_save_param echo %time% end excute step3 >> %log_path% :: 导出 scope 相关的表 :step4 echo %time% begin excute step4 >> %log_path% :: 循环导出 obj 数组中的表 set currentIndex=0 :exportStartLoop if %currentIndex% EQU %tableCounts% goto:exportEndLoop for /f "usebackq delims==. tokens=1-3" %%i in (`set obj[%currentIndex%]`) do ( set curObj.%%j=%%k ) set export_ingnore_table=%export_ingnore_table% --ignore-table=%database_scope%.%curObj.table% if %currentIndex% LSS %param_tableIndex% ( set /a currentIndex=%currentIndex% + 1 goto:exportStartLoop ) echo %time% begin export table %curObj.table% echo %time% begin export table %curObj.table% >> %log_path% set tryCount=0 :: 导出失败进行 3 次尝试 :exporttable if %tryCount% EQU 3 ( echo 导出表 %curObj.table% 失败 无法继续 请联系软件工程人员 echo. pause exit 0 ) if %param_day% EQU 0 ( mysqldump -h%mysqlServer% -u%mysqlUser% -p%mysqlPassword% --no-data --databases %database_scope% --tables %curObj.table% > %param_volume%\%dataSavePath%\%curObj.table%.sql 2>>%log_path% ) else ( mysqldump -h%mysqlServer% -u%mysqlUser% -p%mysqlPassword% --databases %database_scope% --tables %curObj.table% --where="%curObj.field%>date_sub(curdate(), interval %param_day% day)" > %param_volume%\%dataSavePath%\%curObj.table%.sql 2>>%log_path% ) if %errorlevel% NEQ 0 ( echo %time% failed to export table:%curObj.table% >> %log_path% set /a tryCount=%tryCount% + 1 goto:exporttable ) echo %time% end export table %curObj.table% echo. echo %time% end export table %curObj.table% >> %log_path% set /a currentIndex=%currentIndex% + 1 set /a param_tableIndex=%currentIndex% call:fun_save_param goto:exportStartLoop :exportEndLoop :: 导出 scope 库 set tryCount=0 :exportscope if %tryCount% EQU 3 ( echo 导出库 %database_scope% 失败 无法继续 请联系软件工程人员 echo. pause exit 0 ) if %database_scope%% NEQ null ( echo %time% begin export database %database_scope% echo %time% begin export database %database_scope% : %export_ingnore_table% >> %log_path% mysqldump -h%mysqlServer% -u%mysqlUser% -p%mysqlPassword% --databases --events --routines %export_ingnore_table%> %param_volume%\%dataSavePath%\%database_scope%.sql 2>>%log_path% echo %time% end export database %database_scope% echo. echo %time% end export database %database_scope% >> %log_path% ) if %errorlevel% NEQ 0 ( echo %time% failed to export database:%database_scope% >> %log_path% set /a tryCount=%tryCount% + 1 goto:exportscope ) set param_step=5 call:fun_save_param echo %time% end excute step4 >> %log_path% :: 导出fa300 库 :step5 echo %time% begin excute step5 >> %log_path% set tryCount=0 :exportfa300 if %tryCount% EQU 3 ( echo 导出库 %database_fa300% 失败 无法继续 请联系软件工程人员 echo. pause exit 0 ) if %database_fa300% NEQ null ( echo %time% begin export database %database_fa300% echo %time% begin export database %database_fa300% >> %log_path% mysqldump -h%mysqlServer% -u%mysqlUser% -p%mysqlPassword% --databases --events --routines %database_fa300% > %param_volume%\%dataSavePath%\%database_fa300%.sql 2>>%log_path% echo %time% end export database %database_fa300% echo. echo %time% end export database %database_fa300% >> %log_path% ) if %errorlevel% NEQ 0 ( echo %time% failed to export database:%database_fa300% >> %log_path% set /a tryCount=%tryCount% + 1 goto:exportfa300 ) set param_step=6 set param_tableIndex=0 call:fun_save_param echo ********** export data successfully *********** echo. echo %time% exprot data successfully >> %log_path% echo %time% end excute step5 >> %log_path% :: 将干净的 ibdata 替换至客户端 :step6 echo %time% begin excute step6 >> %log_path% echo %time% begin stop mysql echo %time% begin stop mysql >> %log_path% call:fun_stopmysql echo %time% end stop mysql echo. set tryCount=0 :replace :: 三次失败尝试,如果都失败,就需要收到操作 set /a tryCount=%tryCount% + 1 if %tryCount% EQU 4 ( echo !!!!!替换 %param_ibdataPath% 失败!!!!! echo. echo 请手动将脚本目录下 ibdata1 文件替换至 %param_ibdataPath% echo. pause set param_step=7 call:fun_save_param exit 0 ) ::替换 ibdata1 文件 echo %time% begin replace ibdata1 echo %time% begin replace ibdata1 >> %log_path% copy /Y/V/Z ibdata1 "%param_ibdataPath%" if %errorlevel% NEQ 0 goto:replace echo %time% end replace ibdata1 echo. echo %time% end replace ibdata1 >> %log_path% set param_step=7 call:fun_save_param echo ********** replace ibdate1 successfully *********** echo. echo %time% end excute step6 >> %log_path% :step7 echo %time% begin excute step7 >> %log_path% echo %time% begin start mysql echo %time% begin start mysql >> %log_path% call:fun_startmysql echo %time% end start mysql echo. echo %time% end start mysql >> %log_path% :: 导入fa300库 set tryCount=0 :importfa300 if %tryCount% EQU 3 ( echo 导入库 %database_fa300% 失败 无法继续 请联系软件工程人员 echo. pause exit 0 ) if %database_fa300% NEQ null ( echo %time% begin import basedata %database_fa300% echo %time% begin import basedata %database_fa300% >> %log_path% mysql -h %mysqlServer% -u %mysqlUser% -p%mysqlPassword% < %param_volume%\%dataSavePath%\%database_fa300%.sql 2>>%log_path% echo %time% end import basedata %database_fa300% echo. echo %time% end import basedata %database_fa300% >> %log_path% ) if %errorlevel% NEQ 0 ( echo %time% failed to import database:%database_fa300% >> %log_path% set /a tryCount=%tryCount% + 1 goto:importfa300 ) set param_step=8 call:fun_save_param echo %time% end excute step7 >> %log_path% :step8 echo %time% begin excute step8 >> %log_path% call:fun_startmysql :: 导入 scope 库 set tryCount=0 :importscope if %tryCount% EQU 3 ( echo 导入库 %database_scope% 失败 无法继续 请联系软件工程人员 echo. pause exit 0 ) if %database_scope% NEQ null ( echo %time% begin import basedata %database_scope% echo %time% begin import basedata %database_scope% >> %log_path% mysql -h %mysqlServer% -u %mysqlUser% -p%mysqlPassword% < %param_volume%\%dataSavePath%\%database_scope%.sql 2>>%log_path% echo %time% end import basedata %database_scope% echo. echo %time% end import basedata %database_scope% >> %log_path% ) if %errorlevel% NEQ 0 ( echo %time% failed to import database:%database_scope% >> %log_path% set /a tryCount=%tryCount% + 1 goto:importscope ) set param_step=9 call:fun_save_param echo %time% end excute step8 >> %log_path% :step9 echo %time% begin excute step9 >> %log_path% call:fun_startmysql :: 循环导入数组中的表 :importStartLoop if %param_tableIndex% EQU %tableCounts% goto:importEndLoop for /f "usebackq delims==. tokens=1-3" %%i in (`set obj[%param_tableIndex%]`) do ( set curObj.%%j=%%k ) echo %time% begin import table %curObj.table% echo echo %time% begin import table %curObj.table% >> %log_path% set tryCount=0 :importtable if %tryCount% EQU 3 ( echo 导入表 %curObj.table% 错误无法继续,请联系软件工程人员处理 echo. pause exit 0 ) mysql -h %mysqlServer% -u %mysqlUser% -p%mysqlPassword% %database_scope% < %param_volume%\%dataSavePath%\%curObj.table%.sql 2>>%log_path% if %errorlevel% NEQ 0 ( echo %time% failed to import table:%curObj.table% >> %log_path% set /a tryCount=%tryCount%+1 goto:importtable ) echo %time% end import table %curObj.table% echo. echo %time% end import table %curObj.table% >> %log_path% set /a param_tableIndex=%param_tableIndex% + 1 call:fun_save_param goto:importStartLoop :importEndLoop set param_step=10 call:fun_save_param echo %time% end excute step9 >> %log_path% echo ********* imported data successfully *********** echo. :: 校验表是否导入 :step10 echo %time% begin check results echo %time% begin check results >> %log_path% set currentIndex=0 :checkStartLoop if %currentIndex% EQU %tableCounts% goto:checkEndLoop for /f "usebackq delims==. tokens=1-3" %%i in (`set obj[%currentIndex%]`) do ( set curObj.%%j=%%k ) mysql -h %mysqlServer% -u %mysqlUser% -p%mysqlPassword% %database_scope% -e "select %curObj.field% from %curObj.table% limit 1" >>%log_path% 2>&1 if %errorlevel% NEQ 0 ( echo %curObj.table% 表校验失败,请联系软件工程师处理!!! echo. pause exit 0 ) set /a currentIndex=%currentIndex% + 1 goto:checkStartLoop :checkEndLoop echo %time% end check results echo %time% end check results >> %log_path% echo ******** program executed successfully ******** echo. rename %param_volume%\%dataSavePath% %database_scope%_%var_date% >> %log_path% 2>&1 del /Q/F %process_param% >> %log_path% 2>&1 :: 计算任务执行时间 set end_time=%time% echo end time %end_time% call:fun_time_diff %begin_time%,%end_time% echo total time %excute_h%:%excute_m%:%excute_s% pause :fun_time_diff set param1=%1 set param2=%2 set /a h1=%param1:~0,2% 2>nul set /a m1=1%param1:~3,2% - 100 2>nul set /a s1=1%param1:~6,2% - 100 2>nul set /a h2=%param2:~0,2% 2>nul set /a m2=1%param2:~3,2% - 100 2>nul set /a s2=1%param2:~6,2% - 100 2>nul if %h2% LSS %h1% set /a h2=%h2%+24 set /a ts1=%h1%*3600 + %m1%*60 + %s1% set /a ts2=%h2%*3600 + %m2%*60 + %s2% set /a ts=%ts2% - %ts1% set /a excute_h=%ts%/3600 set /a excute_m=(%ts%-%excute_h%*3600)/60 set /a excute_s=%ts%%%%(60) goto:EOF :fun_save_param echo param_date=%date:~0,10%>%process_param% echo step=%param_step% >>%process_param% echo day=%param_day% >>%process_param% echo volume=%param_volume%>>%process_param% echo ibdataPath=%param_ibdataPath%>>%process_param% echo tableIndex=%param_tableIndex% >>%process_param% goto:EOF :fun_stopmysql tasklist|find /i "mysqld.exe" >> %log_path% 2>&1 if %errorlevel% NEQ 0 goto:EOF if %handwork% EQU 0 goto:stopmysql echo !!!!!! 请手动停止mysql 服务,然后继续 !!!!!! echo. pause echo. goto:fun_stopmysql ::使用命令停止 mysql 服务 :stopmysql net stop mysql >> %log_path% 2>&1 if %errorlevel% NEQ 0 set handwork=1 goto:fun_stopmysql goto:EOF :fun_startmysql tasklist|find /i "mysqld.exe" >> %log_path% 2>&1 if %errorlevel% EQU 0 goto:EOF if %handwork% EQU 0 goto:startmysql echo !!!!!!请手动启动 mysql 服务,然后继续!!!!!! echo. pause echo. goto:fun_startmysql :startmysql net start mysql >> %log_path% 2>&1 if %errorlevel% NEQ 0 set handwork=1 goto:fun_startmysql goto:EOF
最新发布
06-20
@echo off %1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit cd /d "%~dp0" echo The beginning of Init Database. echo Running initdb.bat... :param set user=%1 set password=%2 set dir=%3 set data=%4 set port=%5 set port=%port:"=% set encoding=%6 set block_size=%7 set mode=%8 set case-insensitive=%9 set iscase= if %case-insensitive%=="no" ( set iscase=--enable-ci ) ::reset the number for variables shift /1 shift /1 shift /1 shift /1 shift /1 shift /1 shift /1 shift /1 shift /1 ::Authentication Method set AuthenticateMethod=%1 set custom=%2 set custom=%custom:"=% echo custom_value=%custom% ::default means the parameters NOT required set encoding=%encoding:"=% set ENCODE="-E %encoding%" if %encoding%==default ( set ENCODE= ) ::default means the parameters NOT required set allparam=%allparam% %str% shift /0 goto init :init cd /d %dir%\Server\bin\ ::initdb.exe %iskmonitor% %iskfs% -U %user% -x %password% -D %data% --locale=C -E %encoding% --block-size=%block_size% %case-insensitive% -m %mode% initdb.exe -U %user% -x %password% -D %data% --locale=C %ENCODE% --lc-messages=C --block-size=%block_size% %iscase% -m %mode% -A %AuthenticateMethod% %custom% if not %ERRORLEVEL%==0 ( exit ) goto change_port :change_port setlocal enabledelayexpansion cd /d %data% for /f "delims=:" %%a in ('type kingbase.conf^|findstr /nic:"#port = 54321"')do set #%%a=y (for /f "tokens=1* delims=:" %%a in ('type kingbase.conf^|findstr /n .*') do ( if defined #%%a (echo port=%port%)else echo.%%b ))>kingbase_bak.conf move kingbase_bak.conf kingbase.conf echo Init Database Finish.
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值