2010-09-07 78 views
1

我想要制作一个bash脚本来备份db2数据库,然后将其恢复到不同的数据库中。问题在于DB2询问(y/n)问题,并且我无法获得自动回答以使其工作 - 它需要y和回车。bash脚本--DB2“db2恢复数据库”默认答案是

我已经试过以下行(和是命令)寿它好好尝试一下工作

#while true; do echo y; done | db2 restore database $SOURCE taken at $DB2TIME into $TARGET 

RESTORE DATABASE命令执行我从DB2输出后:

SQL2528W Warning! Restoring to an existing database that is the same as the 
backup image database, but the alias name "######" of the existing database 
does not match the alias "$$$$$" of backup image, and the database name 
"#######" of the existing database does not match the database name "$$$$$" of 
the backup image. The target database will be overwritten by the backup 
version. 
Do you want to continue ? (y/n) 

回答

2

使用“无提示”选项

+0

没问题,我只需要使用相同的命令,并在最后放置“无提示”。我试图用'yes'来实现传统的UNIX方式,因为它无法工作 - 无论如何感谢! – edumike 2010-09-07 12:21:52

0

你没有在while循环中试过吗?

echo "y" | db2 ..... 

否则,请检查db2 command man page以关闭交互模式。

+0

我不认为这会产生回车,所以它仍然会坐在那里。我希望有一种方法可以在同一命令“db2 restore database ... yes”中告诉db2默认为yes,但这也不起作用。 – edumike 2010-09-07 01:07:14

3

为什么不直接添加“没有提示”到您的恢复命令。它消除了提示。