技术开发 频道

单机环境快速实践DB2-HADR


自动配置DB2 HADR脚本
@echo off rem ------------------------------------------------------------------ rem 单机环境DB2 HADR生成脚本 rem 您可以将这个脚本保存到一个脚本文件hadr.cmd中,然后按一下语法执行: rem hadr.cmd <hostname> rem ------------------------------------------------------------------ if "%1" == "" goto usage rem ------------------------------------------------------------------ rem 清除原有环境 rem ------------------------------------------------------------------ echo 清除环境 set db2instance=db2inst1 db2start db2 drop db sample db2stop db2idrop db2inst1 set db2instance=db2inst2 db2start db2 drop db sample db2stop db2idrop db2inst2 rem ------------------------------------------------------------------ rem 创建db2inst1实例 rem ------------------------------------------------------------------ echo 创建db2inst1实例.... db2icrt db2inst1 if errorlevel 1 goto end echo 成功创建db2inst1实例 set db2instance=db2inst1 db2start db2 update dbm cfg using svcename 33333 db2set db2comm=tcpip db2 terminate db2stop db2start echo 在实例db2inst1下创建sample数据库 db2sampl if errorlevel 1 goto end db2 update db cfg for sample using LOGRETAIN RECOVERY echo 备份sample数据库到当前路径 db2 backup db sample to . if errorlevel 1 goto end rem ------------------------------------------------------------------ rem 创建db2inst2实例 rem ------------------------------------------------------------------ echo 创建db2inst2实例.... db2icrt db2inst2 if errorlevel 1 goto end echo 成功创建db2inst2实例 set db2instance=db2inst2 db2start db2 update dbm cfg using svcename 44444 db2set db2comm=tcpip db2 terminate db2stop echo 在实例db2inst2下恢复sample数据库 db2start db2 restore db sample from . if errorlevel 1 goto end rem ------------------------------------------------------------------ rem 配置HADR参数 rem ------------------------------------------------------------------ echo 配置实例db2inst2下的sample数据库的HADR参数 db2 update db cfg for sample using HADR_LOCAL_HOST %1 db2 update db cfg for sample using HADR_LOCAL_SVC 44455 db2 update db cfg for sample using HADR_REMOTE_HOST %1 db2 update db cfg for sample using HADR_REMOTE_SVC 33344 db2 update db cfg for sample using HADR_REMOTE_INST db2inst1 db2 update db cfg for sample using HADR_SYNCMODE NEARSYNC db2 update db cfg for sample using LOGINDEXBUILD on echo 配置实例db2inst1下的sample数据库的HADR参数 SET db2instance=db2inst1 db2 update db cfg for sample using HADR_LOCAL_HOST %1 db2 update db cfg for sample using HADR_LOCAL_SVC 33344 db2 update db cfg for sample using HADR_REMOTE_HOST %1 db2 update db cfg for sample using HADR_REMOTE_SVC 44455 db2 update db cfg for sample using HADR_REMOTE_INST db2inst2 db2 update db cfg for sample using HADR_SYNCMODE NEARSYNC db2 update db cfg for sample using LOGINDEXBUILD on rem ------------------------------------------------------------------ rem 启动HADR rem ------------------------------------------------------------------ echo 启动实例db2inst2下的sample数据库作为备用数据库standby set db2instance=db2inst2 db2 start hadr on db sample as standby if errorlevel 1 goto end echo 启动实例db2inst1下的sample数据库作为主数据库primary set db2instance=db2inst1 db2 start hadr on db sample as primary if errorlevel 1 goto end echo 祝贺您成功配置HADR. exit :usage echo "语法: handson.cmd <hostname>" :end Echo "运行错误,请检查脚本"
0
相关文章