我正在尝试使用脚本为我的DB2(10.1.0)执行脱机备份并安排它。
db2backup.bat
@ECHO OFF
FOR xxxx IN (OPNACT BLOGS SNCOMM DOGEAR FILES FORUM HOMEPAGE PEOPLEDB WIKIS) DO (
DB2 CONNECT TO xxxx
DB2 QUIESCE DATABASE IMMEDIATE FORCE CONNECTIONS
DB2 CONNECT RESET
DB2 BACKUP DATABASE xxxx TO "C:\Backup\DB2" WITH 2 BUFFERS BUFFER 1024 PARALLELISM 3 WITHOUT PROMPTING
DB2 CONNECT TO xxxx
DB2 UNQUIESCE DATABASE
DB2 CONNECT RESET
)
但是当我尝试运行它时,
DB2CMD /c /w /i C:\Backup\db2backup.bat
我收到了错误,
" xxxx此时出乎意料。"
所以我为什么要这个?我怎么能避免它?
非常感谢您的投入!!
答案 0 :(得分:0)
问题在于你如何处理变量。 xxxxx不是有效名称,应该以两个百分比开头:%% xxxxx
@ECHO OFF
FOR %%xxxx IN (OPNACT BLOGS SNCOMM DOGEAR FILES FORUM HOMEPAGE PEOPLEDB WIKIS) DO (
DB2 CONNECT TO %%xxxx
DB2 QUIESCE DATABASE IMMEDIATE FORCE CONNECTIONS
DB2 CONNECT RESET
DB2 BACKUP DATABASE %%xxxx TO "C:\Backup\DB2" WITH 2 BUFFERS BUFFER 1024 PARALLELISM 3 WITHOUT PROMPTING
DB2 CONNECT TO %%xxxx
DB2 UNQUIESCE DATABASE
DB2 CONNECT RESET
)
有关详细信息,请查看此问题What is the difference between % and %% in a cmd file?