7. 恢复测试机数据文件
RMAN> restore database;
Starting restore at 12-OCT-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 10/12/2014 17:43:29
ORA-01220: file based sort illegal before database is open
RMAN> host!
[Oracle@bak ~]$ oerr ora 01220
01220, 00000, "file based sort illegal before database is open"
// *Cause: A query issued against a fixed table or view required a temporary
// segment for sorting before the database was open. Only in-memory
// sorts are supported before the database is open.
// *Action: Re-phrase the query to avoid a large sort, increase the values
// of the SORT_AREA_SIZE and/or SORT_AREA_RETAINED_SIZE
// initialization parameters to enable the sort to be done in memory.
SQL> show parameter sort_
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
sort_area_retained_size integer 0
sort_area_size integer 65536
查看源库也是这个配置,感觉提示中增加SORT_AREA_SIZE and/or SORT_AREA_RETAINED_SIZE是误导,怀疑是pga_aggregate_target设置为0引起的,有点不解的是,为什么RMAN做restore database还需要用到排序区
[oracle@bak ~]$ vim $ORACLE_HOME/dbs/initora10g.ora
...
*.pga_aggregate_target=90M --调整到和源库一致
...
调整完该参数后重启实例,再连接RMAN尝试一次
SQL> startup nomount force
ORACLE instance started.
Total System Global Area 1073741824 bytes
Fixed Size 1223512 bytes
Variable Size 264242344 bytes
Database Buffers 805306368 bytes
Redo Buffers 2969600 bytes
SQL> show parameter pga
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target big integer 90M
[oracle@bak ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Sun Oct 12 17:59:06 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ora10g (not mounted)
RMAN> restore database;
Starting restore at 12-OCT-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 10/12/2014 17:59:15
ORA-01507: database not mounted
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN> restore database;
Starting restore at 12-OCT-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/ora10g/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/ora10g/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/ora10g/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/ora10g/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/ora10g/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/ora10g/zlm01.dbf
channel ORA_DISK_1: reading from backup piece /u01/orabackup/backupsets/ora10g-4175411955_20141012_860776704_316.db
ORA-19870: error reading backup piece /u01/orabackup/backupsets/ora10g-4175411955_20141012_860776704_316.db
ORA-19505: failed to identify file "/u01/orabackup/backupsets/ora10g-4175411955_20141012_860776704_316.db"
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
failover to previous backup
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/ora10g/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/ora10g/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/ora10g/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/ora10g/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/ora10g/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/ora10g/zlm01.dbf
channel ORA_DISK_1: reading from backup piece /u01/orabackup/backupsets/ora10g-4175411955_20141011_860666488_312.db
ORA-19870: error reading backup piece /u01/orabackup/backupsets/ora10g-4175411955_20141011_860666488_312.db
ORA-19505: failed to identify file "/u01/orabackup/backupsets/ora10g-4175411955_20141011_860666488_312.db"
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
failover to previous backup
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/ora10g/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/ora10g/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/ora10g/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/ora10g/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/ora10g/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/ora10g/zlm01.dbf
channel ORA_DISK_1: reading from backup piece /u01/orabackup/backupsets/ora10g-4175411955_20140928_859456907_308.db
ORA-19870: error reading backup piece /u01/orabackup/backupsets/ora10g-4175411955_20140928_859456907_308.db
ORA-19505: failed to identify file "/u01/orabackup/backupsets/ora10g-4175411955_20140928_859456907_308.db"
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
failover to previous backup
creating datafile fno=6 name=/u01/app/oracle/oradata/ora10g/zlm01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 10/12/2014 17:59:33
ORA-01119: error in creating database file '/u01/app/oracle/oradata/ora10g/zlm01.dbf'
ORA-27040: file create error, unable to create file
Linux Error: 2: No such file or directory
RMAN>
注意,这里有2个问题:
1.找备份集的路径为/u01/orabackup/backupsets/,而在测试机上并没有此路径,之前只是把备份集复制到了/tmp目录下面而已,而且可以发现一个很有趣的现象,除了找最新的备份集xxx_316.db之外,还会往前去找之前的xxx_312.db,xxx_308这2个备份集,当然,这也是找不到的
2.刚才在初始化参数中还修改过了数据文件路径,对于这些信息的改变,刚恢复出来的控制文件自然是不知道的
对于第1个问题,需要把备份集的新位置告知RMAN,可以用catalog start with 'xxx'
对于第2个问题,需要用set newname for datafile xxx 来调整,并用run脚本运行
RMAN> catalog start with '/tmp';
searching for all files that match the pattern /tmp
no files found to be unknown to the database
RMAN> exit
Recovery Manager complete.
[root@bak ~]# ll / |grep tmp
drwxrwxrwx 4 root root 4096 Oct 12 18:28 tmp
[oracle@bak ~]$ ll /tmp
total 181172
srwxr-xr-x 1 root root 0 Aug 22 13:28 mapping-root
-rw-r----- 1 oracle oinstall 4440064 Oct 12 16:46 ora10g-4175411955_20141012_860776699_315.arc
-rw-r----- 1 oracle oinstall 172843008 Oct 12 16:47 ora10g-4175411955_20141012_860776704_316.db
-rw-r----- 1 oracle oinstall 427520 Oct 12 16:47 ora10g-4175411955_20141012_860776830_317.arc
-rw-r----- 1 oracle oinstall 7602176 Oct 12 16:47 ora10g-c-4175411955-20141012-00.ctl
srw------- 1 root root 0 Aug 22 13:28 scim-panel-socket:0-root
尽管备份集在tmp目录下,但是属主为root,RMAN自然无法对其进行操作。而对于tmp目录,也不方便把它作为oracle自己的目录,因为系统本身也会对该目录进行操作。由于那么我们为oracle用户单独创建个目录存放这些归档日志,并赋予权限
[root@bak ~]# mkdir /oracle/backupsets -p
[root@bak ~]# chmod 755 /oracle/backupsets -R
[root@bak ~]# mv /tmp/*20141012* /oracle/backupsets
[oracle@bak ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Sun Oct 12 18:31:16 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORA10G (DBID=4175411955, not open)
RMAN> catalog start with '/oracle/backupsets';
using target database control file instead of recovery catalog
searching for all files that match the pattern /oracle/backupsets
List of Files Unknown to the Database
=====================================
File Name: /oracle/backupsets/ora10g-4175411955_20141012_860776704_316.db
File Name: /oracle/backupsets/ora10g-4175411955_20141012_860776830_317.arc
File Name: /oracle/backupsets/ora10g-c-4175411955-20141012-00.ctl
File Name: /oracle/backupsets/ora10g-4175411955_20141012_860776699_315.arc
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /oracle/backupsets/ora10g-4175411955_20141012_860776704_316.db
File Name: /oracle/backupsets/ora10g-4175411955_20141012_860776830_317.arc
File Name: /oracle/backupsets/ora10g-c-4175411955-20141012-00.ctl
File Name: /oracle/backupsets/ora10g-4175411955_20141012_860776699_315.arc
RMAN>
现在可以把目录catalog到控制文件了,其实ora10g-c-4175411955-20141012-00.ctl已经用不到,我们需要的是.db,.arc这几个备份集
RMAN>run{
set newname for datafile 1 to"/oradata/ora10g/system01.dbf";
set newname for datafile 2 to"/oradata/ora10g/undotbs01.dbf";
set newname for datafile 3 to"/oradata/ora10g/sysaux01.dbf";
set newname for datafile 4 to"/oradata/ora10g/users01.dbf";
set newname for datafile 5 to"/oradata/ora10g/example01.dbf";
set newname for datafile 6 to"/oradata/ora10g/zlm01.dbf";
restore database;
switch datafile all;
}
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 12-OCT-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /oradata/ora10g/system01.dbf
restoring datafile 00002 to /oradata/ora10g/undotbs01.dbf
restoring datafile 00003 to /oradata/ora10g/sysaux01.dbf
restoring datafile 00004 to /oradata/ora10g/users01.dbf
restoring datafile 00005 to /oradata/ora10g/example01.dbf
restoring datafile 00006 to /oradata/ora10g/zlm01.dbf
channel ORA_DISK_1: reading from backup piece /u01/orabackup/backupsets/ora10g-4175411955_20141012_860776704_316.db
channel ORA_DISK_1: restored backup piece 1
failover to piece handle=/oracle/backupsets/ora10g-4175411955_20141012_860776704_316.db tag=DB_BAK
channel ORA_DISK_1: restore complete, elapsed time: 00:02:17
Finished restore at 12-OCT-14
datafile 1 switched to datafile copy
input datafile copy recid=18 stamp=860783911 filename=/oradata/ora10g/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=19 stamp=860783911 filename=/oradata/ora10g/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=20 stamp=860783911 filename=/oradata/ora10g/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=21 stamp=860783911 filename=/oradata/ora10g/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=22 stamp=860783911 filename=/oradata/ora10g/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=23 stamp=860783911 filename=/oradata/ora10g/zlm01.dbf
RMAN>
注意,这里会有一个failover to的操作,先是去/u01/orabackup/backupsets读取,但是发现没有,但不会像之前那么样报错,而是转到了刚才我们catalog过的目录“/oracle/backupsets”中去读取,这次很顺利就把数据文件恢复出来了
[oracle@bak ~]$ ll -lrth /oradata/ora10g/
total 1.2G
-rw-r----- 1 oracle oinstall 21M Oct 12 18:36 zlm01.dbf
-rw-r----- 1 oracle oinstall 31M Oct 12 18:36 users01.dbf
-rw-r----- 1 oracle oinstall 101M Oct 12 18:36 example01.dbf
-rw-r----- 1 oracle oinstall 166M Oct 12 18:37 undotbs01.dbf
-rw-r----- 1 oracle oinstall 271M Oct 12 18:37 sysaux01.dbf
-rw-r----- 1 oracle oinstall 561M Oct 12 18:38 system01.dbf
-rw-r----- 1 oracle oinstall 7.2M Oct 12 18:50 control03.ctl
-rw-r----- 1 oracle oinstall 7.2M Oct 12 18:50 control02.ctl
-rw-r----- 1 oracle oinstall 7.2M Oct 12 18:50 control01.ctl
