出错原因是switch datafile all需要放在run块里,且不能是单独的run块,需要和restore放在一起,额外执行是不行的,下面是出错的日志
RMAN> run {
2> SET NEWNAME FOR DATABASE TO '/oradata/%U';
3> restore database;
4> }
executing command: SET NEWNAME
Starting restore at 25-NOV-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /oradata/data_D-ORCL_TS-SYSTEM_FNO-1
channel ORA_DISK_1: restoring datafile 00002 to /oradata/data_D-ORCL_TS-SYSAUX_FNO-2
channel ORA_DISK_1: restoring datafile 00003 to /oradata/data_D-ORCL_TS-UNDOTBS1_FNO-3
channel ORA_DISK_1: restoring datafile 00004 to /oradata/data_D-ORCL_TS-USERS_FNO-4
channel ORA_DISK_1: reading from backup piece /backup/orcl_full_01rlpite_1_1
channel ORA_DISK_1: piece handle=/backup/orcl_full_01rlpite_1_1 tag=TAG20161125T075213
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
Finished restore at 25-NOV-16
RMAN> recover database;
Starting recover at 25-NOV-16
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 11/25/2016 08:03:56
RMAN-06094: datafile 1 must be restored
RMAN> switch datafile all;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "all": expecting one of: "double-quoted-string, integer, single-quoted-string"
RMAN-01007: at line 1 column 17 file: standard input
RMAN> run {
2> switch datafile all;
3> }
RMAN> recover database;
Starting recover at 25-NOV-16
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 11/25/2016 08:05:13
RMAN-06094: datafile 1 must be restored
将switch datafile all和restore放在同一个run块里执行就没问题了。