命令窗口不会关闭

时间:2018-01-09 11:57:52

标签: batch-file db2 exit

我正在运行一个简单的批处理文件来备份一个小型数据库。工作正常,但不会关闭命令提示符。

完成批处理文件,如下所示:

db2cmd.exe -i db2stop force
PING localhost -n 6 >NUL
db2cmd.exe -i db2start
PING localhost -n 6 >NUL
db2cmd.exe -i db2 backup database icmnlsdb to e:\backup
PING localhost -n 6 >NUL
db2cmd.exe -i db2 backup database rmdb to e:\backup

我已经尝试添加退出...没有去。 尝试了我在其他地方看到的建议。

添加这些行无济于事:

 goto eof
 :eof
 exit

仍然没有反应;只是保持开放

2 个答案:

答案 0 :(得分:0)

尝试不同的方法,在下面的代码片段中更改db2cmd值以适合您的环境。如果仍然遇到问题,请编辑问题以添加db2level命令的输出,并在脚本运行时显示db2diag.log文件中的条目。

@set db2cmd="C:\Program Files\IBM\SQLLIB\BIN\db2cmd.exe"
@if "%DB2CLP%"=="" %db2cmd% /w /c /i "%0" %* && @goto :EOF
set bkpdir=e:\backup
@if not exist %bkpdir% @echo "Directory %bkpdir% does not exist" && @goto :failEOF
db2stop force
@if errorlevel 1 @echo "Failed to stop Db2 but ignoring this"
db2start
@if errorlevel 4 @echo "Failed to start Db2" && @goto :failEOF
db2 -v backup database icmnlsdb to %bkpdir%
@if errorlevel 1 @echo "Failed to backup icmnlsdb" && @goto :failEOF
db2 -v backup database rmdb to %bkpdir%
@if errorlevel 1 @echo "Failed to backup rmdb" && @goto :failEOF
@echo "Db2 database backups completed successfully"
@exit /b 0
:failEOF
@rem You should add alerting (emails or other notifications) here
@echo "The Db2 offline backups failed"
@exit /b 1

除此之外,您还应考虑使用Db2在线备份,因为这样可以让您配置Db2以自动执行备份计划,管理备份映像的保留,管理故障通知,并且不会中断连接的应用程序。 / p>

答案 1 :(得分:0)

感谢加拿大的mustaccio ....在发布之后在其他地方找到了答案。

只需添加/ c开关:

db2cmd.exe -i db2stop force
PING localhost -n 6 >NUL
db2cmd.exe -i db2start
PING localhost -n 6 >NUL
db2cmd.exe -i db2 backup database icmnlsdb to e:\backup
PING localhost -n 6 >NUL
db2cmd.exe -i db2 backup database rmdb to e:\backup

像魅力一样工作。没有更多命令框。