还原种子数据库练习

种子数据库的控制文件位置:
$ORACLE_HOME/assistants/dbca/templates/Seed_Database.ctl
种子数据库的备份片位置:
$ORACLE_HOME/assistants/dbca/templates/Seed_Database.dfb
 
大体步骤如下:
编辑一个pfile启动到nomount,然后通过控制文件启动到mount状态,恢复数据库文件,然后启动数据库

 
1. 随便编辑一个pfile,只添加上Db_name和控制文件路径即可
[oracle@elvis-desktop dbs]$ vi initORCL.ora
db_name='ORCL'
control_files='/oracle/oradata/ORCL/control1.ctl'
 
2. 定义一个ORACLE_SID,创建存放数据库文件的目录
[oracle@elvis-desktop dbs]$ export ORACLE_SID=ORCL
[oracle@elvis-desktop dbs]$ mkdir /oracle/oradata/ORCL/
 
3. 把种子数据库的控制文件拷贝到pfile中的路径,并且修改成相应的名字,使用pfile启动到nomount状态
[oracle@elvis-desktop dbs]$ rman target /
 
Recovery Manager: Release 11.2.0.3.0 - Production on Thu Sep 5 13:45:33 2013
 
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
 
connected to target database (not started)
 
RMAN> startup nomount pfile='/oracle/product/11.2.0/dbhome_1/dbs/initORCL.ora';
 
Oracle instance started
 
Total System Global Area 238034944 bytes
 
Fixed Size 2227136 bytes
Variable Size 180356160 bytes
Database Buffers 50331648 bytes
Redo Buffers 5120000 bytes
4. 启动数据库到mount状态
RMAN> alter database mount;
 
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 09/05/2013 13:52:32
ORA-01103: database name 'SEEDDATA' in control file is not 'ORCL'
------->>> 此处报数据库的名字为SEEDDATA,将pfile中的db_name修改成SEEDDATA,重启数据库,启动到mount状态
[oracle@elvis-desktop dbs]$ vi initORCL.ora
db_name='SEEDDATA'
control_files='/oracle/oradata/ORCL/control01.ctl'
 
RMAN> alter database mount;
 
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 09/05/2013 13:53:12
ORA-01103: database name 'SEEDDATA' in control file is not 'ORCL'
RMAN> shutdown abort;
Oracle instance shut down
RMAN> startup nomount pfile='/oracle/product/11.2.0/dbhome_1/dbs/initORCL.ora';
 
connected to target database (not started)
Oracle instance started
 
Total System Global Area 238034944 bytes
 
Fixed Size 2227136 bytes
Variable Size 180356160 bytes
Database Buffers 50331648 bytes
Redo Buffers 5120000 bytes
 
RMAN> alter database mount;
database mounted
5. 注册数据库备份片的位置,开始恢复数据库
RMAN> catalog start with '/oracle/product/11.2.0/dbhome_1/assistants/dbca/templates/Seed_Database.dfb';
searching for all files that match the pattern /oracle/product/11.2.0/dbhome_1/assistants/dbca/templates/Seed_Database.dfb
 
List of Files Unknown to the Database
=====================================
File Name: /oracle/product/11.2.0/dbhome_1/assistants/dbca/templates/Seed_Database.dfb
 
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/product/11.2.0/dbhome_1/assistants/dbca/templates/Seed_Database.dfb
RMAN> crosscheck backup; ----->>>检查备份集的有效性
using channel ORA_DISK_1
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/ade/b/385031636/oracle/oradata/Seed_Database.dfb RECID=1 STAMP=762085401
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/oracle/product/11.2.0/dbhome_1/assistants/dbca/templates/Seed_Database.dfb RECID=2 STAMP=825342912
Crosschecked 2 objects
RMAN> delete expired backup; ----->>>>删除过期备份
using channel ORA_DISK_1
 
List of Backup Pieces
BP Key BS Key Pc# Cp# Status Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
1 1 1 1 EXPIRED DISK /ade/b/385031636/oracle/oradata/Seed_Database.dfb
 
Do you really want to delete the above objects (enter YES or NO)? YES
deleted backup piece
backup piece handle=/ade/b/385031636/oracle/oradata/Seed_Database.dfb RECID=1 STAMP=762085401
Deleted 1 EXPIRED objects
 
RMAN> list backup; ----->>>>检查备份集的相关信息
 
 
List of Backup Sets
===================
 
 
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1 Full 253.38M DISK 00:00:58 17-SEP-11
BP Key: 2 Status: AVAILABLE Compressed: YES Tag:
Piece Name: /oracle/product/11.2.0/dbhome_1/assistants/dbca/templates/Seed_Database.dfb
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 995547 17-SEP-11 /ade/b/385031636/oracle/oradata/seeddata/system01.dbf
2 Full 995547 17-SEP-11 /ade/b/385031636/oracle/oradata/seeddata/sysaux01.dbf
3 Full 995547 17-SEP-11 /ade/b/385031636/oracle/oradata/seeddata/undotbs01.dbf
4 Full 995547 17-SEP-11 /ade/b/385031636/oracle/oradata/seeddata/users01.dbf
------->>> 上述检查后,我们就该知道要修改数据文件的名字到新的目录
RMAN> restore database;
 
Starting restore at 05-SEP-13
using channel ORA_DISK_1
 
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 /ade/b/385031636/oracle/oradata/seeddata/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /ade/b/385031636/oracle/oradata/seeddata/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /ade/b/385031636/oracle/oradata/seeddata/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /ade/b/385031636/oracle/oradata/seeddata/users01.dbf
channel ORA_DISK_1: reading from backup piece /oracle/product/11.2.0/dbhome_1/assistants/dbca/templates/Seed_Database.dfb
channel ORA_DISK_1: ORA-19870: error while restoring backup piece /oracle/product/11.2.0/dbhome_1/assistants/dbca/templates/Seed_Database.dfb
ORA-19504: failed to create file "/ade/b/385031636/oracle/oradata/seeddata/system01.dbf"
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 1
 
failover to previous backup
 
creating datafile file number=1 name=/ade/b/385031636/oracle/oradata/seeddata/system01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 09/05/2013 13:59:56
ORA-01180: can not create datafile 1
ORA-01110: data file 1: '/ade/b/385031636/oracle/oradata/seeddata/system01.dbf'
-------------------->>>>果然提示报错,不能创建相关的目录。我们要修改到指定的位置/oracle/oradata/ORCL/
-------------------->>>>修改数据库文件名字,switch datafile all就是更新控制文件的意思
RMAN> run
{
set newname for datafile '/ade/b/385031636/oracle/oradata/seeddata/system01.dbf' to '/oracle/oradata/ORCL/system01.dbf';
set newname for datafile '/ade/b/385031636/oracle/oradata/seeddata/sysaux01.dbf' to '/oracle/oradata/ORCL/sysaux01.dbf';
set newname for datafile '/ade/b/385031636/oracle/oradata/seeddata/undotbs01.dbf' to '/oracle/oradata/ORCL/undotbs01.dbf';
set newname for datafile '/ade/b/385031636/oracle/oradata/seeddata/users01.dbf' to '/oracle/oradata/ORCL/users01.dbf';
restore database;
switch datafile all;
recover database;
}
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
Starting restore at 05-SEP-13
using channel ORA_DISK_1
 
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 /oracle/oradata/ORCL/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /oracle/oradata/ORCL/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /oracle/oradata/ORCL/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /oracle/oradata/ORCL/users01.dbf
channel ORA_DISK_1: reading from backup piece /oracle/product/11.2.0/dbhome_1/assistants/dbca/templates/Seed_Database.dfb
channel ORA_DISK_1: piece handle=/oracle/product/11.2.0/dbhome_1/assistants/dbca/templates/Seed_Database.dfb tag=NULL
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:05
Finished restore at 05-SEP-13
 
datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=825343689 file name=/oracle/oradata/ORCL/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=825343689 file name=/oracle/oradata/ORCL/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=825343689 file name=/oracle/oradata/ORCL/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=825343689 file name=/oracle/oradata/ORCL/users01.dbf
 
Starting recover at 05-SEP-13
using channel ORA_DISK_1
 
starting media recovery
 
RMAN-08187: WARNING: media recovery until SCN 995547 complete
Finished recover at 05-SEP-13
------------->>>> 成功recover,显示这是个介质恢复,只完成SCN号995547,属于不完全恢复
RMAN> ALTER DATABASE OPEN;
 
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 09/05/2013 14:08:19
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
------------>>>> 由于是介质恢复,所以需要以resetlog的方式打开
RMAN> ALTER DATABASE OPEN RESETLOGS;
 
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 09/05/2013 14:08:25
ORA-00349: failure obtaining block size for '/ade/b/385031636/oracle/oradata/seeddata/redo01.log'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 9
--------- 缺少redo文件,添加3个redo log文件,并且要修改位置
RMAN> ALTER DATABASE OPEN RESETLOGS;
 
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 09/05/2013 14:10:02
ORA-00349: failure obtaining block size for '/ade/b/385031636/oracle/oradata/seeddata/redo03.log'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 9
------ 上述缺少redolog文件,需要建立redo log文件
[oracle@elvis-desktop dbs]$ export ORACLE_SID=ORCL
[oracle@elvis-desktop dbs]$ sqlplus / as sysdba
 
SQL*Plus: Release 11.2.0.3.0 Production on Thu Sep 5 14:08:51 2013
 
Copyright (c) 1982, 2011, Oracle. All rights reserved.
 
 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
SQL> select status from v$instance;
 
STATUS
------------
MOUNTED
 
SQL> alter database rename file '/ade/b/385031636/oracle/oradata/seeddata/redo01.log' to '/oracle/oradata/ORCL/redo01.log';
 
Database altered.
 
SQL> alter database rename file '/ade/b/385031636/oracle/oradata/seeddata/redo02.log' to '/oracle/oradata/ORCL/redo02.log';
 
Database altered.
 
SQL> alter database rename file '/ade/b/385031636/oracle/oradata/seeddata/redo03.log' to '/oracle/oradata/ORCL/redo03.log';
 
Database altered.
RMAN> ALTER DATABASE OPEN RESETLOGS;
 
database opened
 
---------->>>>>> 数据库成功打开,需要做一次全备
[oracle@elvis-desktop dbs]$ sqlplus / as sysdba
 
SQL*Plus: Release 11.2.0.3.0 Production on Thu Sep 5 14:10:52 2013
 
Copyright (c) 1982, 2011, Oracle. All rights reserved.
 
 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
SQL> select status from v$instance;
 
STATUS
------------
OPEN
------------------->>>> 为新数据库创建spfile,并且重启数据库
SQL> create spfile from pfile;
 
File created.
 
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
 
Total System Global Area 238034944 bytes
Fixed Size 2227136 bytes
Variable Size 180356160 bytes
Database Buffers 50331648 bytes
Redo Buffers 5120000 bytes
Database mounted.
Database opened.
SQL> show parameter spfile;
 
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /oracle/product/11.2.0/dbhome_1/dbs/spfileORCL.ora
SQL> show parameter name;
 
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert string
db_name string SEEDDATA
db_unique_name string SEEDDATA
global_names boolean FALSE
instance_name string ORCL
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string SEEDDATA
 
--------------------->>>> 恢复成功,可以看到数据库以spfile启动,并且实例名和数据库名不一样

 

你可能感兴趣的:(数据库)