实验步骤:
1、在目录数据库中创建恢复目录所用表空间:
SQL> create tablespace rmants datafile '/opt/oracle/db02/oradata/ORCL/rmants.dbf' size 100M autoextend on next 1M maxsize unlimited;
Tablespace created.
2、在目录数据库中创建RMAN用户并授权:
SQL> create user rman identified by rman default tablespace rmants temporary tablespace temp quota unlimited on rmants;
User created.
SQL> grant recovery_catalog_owner to rman;
Grant succeeded.
3、在目录数据库中创建恢复目录:
$ rman catalog rman/rman
Recovery Manager: Release 9.2.0.4.0 - 64bit Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to recovery catalog database
recovery catalog is not installed
RMAN>create catalog tablespace rmants;
recovery catalog created
4、注册目标数据库到恢复目录
我的目标数据库使用的服务名称是rcat
$ rman target / (在目标数据库上执行该命令,首先用rman连接到目标数据库)
Recovery Manager: Release 8.1.7.3.0 - Production
RMAN-06005: connected to target database: ORCL (DBID=1000277484)
RMAN> connect catalog rman/rman@rcat (连接到catalog目录数据库)
RMAN-06008: connected to recovery catalog database
RMAN> register database; (在catalog目录数据库上注册目标数据库)
RMAN-03022: compiling command: register
RMAN-03023: executing command: register
RMAN-08006: database registered in recovery catalog
RMAN-03023: executing command: full resync
RMAN-08002: starting full resync of recovery catalog
RMAN-08004: full resync complete
准备工作已经作好,下面开始使用RMAN来进行备份和恢复了。
5.做rman全备份:
RMAN> run
{
allocate channel c1 type disk;
backup full tag 'dbfull' format '/opt/oracle/full%u_%p_%c' database include current controlfile;
sql 'alter system archive log current';
backup filesperset 3 archivelog all delete input;
release channel c1;
}
RMAN-03022: compiling command: allocate
RMAN-03023: executing command: allocate
RMAN-08030: allocated channel: c1
RMAN-08500: channel c1: sid=15 devtype=DISK
RMAN-03022: compiling command: backup
RMAN-03023: executing command: backup
RMAN-08008: channel c1: starting full datafile backupset
RMAN-08502: set_count=3 set_stamp=537970127 creation_time=27-SEP-04
RMAN-08010: channel c1: specifying datafile(s) in backupset
RMAN-08522: input datafile fno=00001 name=/opt/oracle/db02/oradata/ORCL/system01.dbf
RMAN-08011: including current controlfile in backupset
RMAN-08522: input datafile fno=00004 name=/opt/oracle/db02/oradata/ORCL/temp01.dbf
RMAN-08522: input datafile fno=00019 name=/opt/oracle/db02/oradata/ORCL/rbs02.dbf
RMAN-08522: input datafile fno=00003 name=/opt/oracle/db02/oradata/ORCL/rbs03.dbf
RMAN-08522: input datafile fno=00002 name=/opt/oracle/db02/oradata/ORCL/tools01.dbf
RMAN-08522: input datafile fno=00006 name=/opt/oracle/db02/oradata/ORCL/indx01.dbf
RMAN-08522: input datafile fno=00005 name=/opt/oracle/db02/oradata/ORCL/users01.dbf
RMAN-08522: input datafile fno=00007 name=/opt/oracle/db02/oradata/ORCL/drsys01.dbf
RMAN-08522: input datafile fno=00010 name=/opt/oracle/db02/oradata/ORCL/test.dbf
RMAN-08013: channel c1: piece 1 created
RMAN-08503: piece handle=/opt/oracle/full03g11hef_1_1 comment=NONE
RMAN-08525: backup set complete, elapsed time: 00:02:55
RMAN-03023: executing command: partial resync
RMAN-08003: starting partial resync of recovery catalog
RMAN-08005: partial resync complete
RMAN-03022: compiling command: sql
RMAN-06162: sql statement: alter system archive log current
RMAN-03023: executing command: sql
RMAN-03022: compiling command: backup
RMAN-03025: performing implicit partial resync of recovery catalog
RMAN-03023: executing command: partial resync
RMAN-08003: starting partial resync of recovery catalog
RMAN-08005: partial resync complete
RMAN-03023: executing command: backup
RMAN-08009: channel c1: starting archivelog backupset
RMAN-08502: set_count=4 set_stamp=537970305 creation_time=27-SEP-04
RMAN-08014: channel c1: specifying archivelog(s) in backup set
RMAN-08504: input archivelog thread=1 sequence=1 recid=7 stamp=537958625
RMAN-08013: channel c1: piece 1 created
RMAN-08503: piece handle=/opt/oracle/db01/app/oracle/product/8.1.7/dbs/04g11hk1_1_1 comment=NONE
RMAN-08525: backup set complete, elapsed time: 00:00:02
RMAN-08071: channel c1: deleting archivelog(s)
RMAN-08514: archivelog filename=/opt/oracle/arch/ORCL/arch_1_1.arc recid=7 stamp=537958625
RMAN-08009: channel c1: starting archivelog backupset
RMAN-08502: set_count=5 set_stamp=537970307 creation_time=27-SEP-04
RMAN-08014: channel c1: specifying archivelog(s) in backup set
RMAN-08504: input archivelog thread=1 sequence=2 recid=8 stamp=537958661
RMAN-08504: input archivelog thread=1 sequence=3 recid=9 stamp=537959443
RMAN-08504: input archivelog thread=1 sequence=4 recid=10 stamp=537970304
RMAN-08013: channel c1: piece 1 created
RMAN-08503: piece handle=/opt/oracle/db01/app/oracle/product/8.1.7/dbs/05g11hk3_1_1 comment=NONE
RMAN-08525: backup set complete, elapsed time: 00:00:02
RMAN-08071: channel c1: deleting archivelog(s)
RMAN-08514: archivelog filename=/opt/oracle/arch/ORCL/arch_1_2.arc recid=8 stamp=537958661
RMAN-08514: archivelog filename=/opt/oracle/arch/ORCL/arch_1_3.arc recid=9 stamp=537959443
RMAN-08514: archivelog filename=/opt/oracle/arch/ORCL/arch_1_4.arc recid=10 stamp=537970304
RMAN-03023: executing command: partial resync
RMAN-08003: starting partial resync of recovery catalog
RMAN-08005: partial resync complete
RMAN-03022: compiling command: release
RMAN-03023: executing command: release
RMAN-08031: released channel: c1
RMAN> exit
Recovery Manager complete.
6.查看数据库备份信息:
$ rman target / catalog rman/rman@rcat
Recovery Manager: Release 8.1.7.3.0 - Production
RMAN-06005: connected to target database: ORCL (DBID=1000277484)
RMAN-06008: connected to recovery catalog database
RMAN>list backup;
RMAN-03022: compiling command: list
List of Backup Sets
Key Recid Stamp LV Set Stamp Set Count Completion Time
------- ---------- ---------- -- ---------- ---------- ----------------------
22 2 537970293 0 537970127 3 27-SEP-04
List of Backup Pieces
Key Pc# Cp# Status Completion Time Piece Name
------- --- --- ----------- ---------------------- ------------------------
23 1 1 AVAILABLE 27-SEP-04 /opt/oracle/full03g11hef_1_1
List of Datafiles Included
File Name LV Type Ckp SCN Ckp Time
---- ------------------------------------- -- ---- ---------- -------------
1 /opt/oracle/db02/oradata/ORCL/system01.dbf 0 Full 5226242 27-SEP-04
2 /opt/oracle/db02/oradata/ORCL/tools01.dbf 0 Full 5226242 27-SEP-04
3 /opt/oracle/db02/oradata/ORCL/rbs03.dbf 0 Full 5226242 27-SEP-04
4 /opt/oracle/db02/oradata/ORCL/temp01.dbf 0 Full 5226242 27-SEP-04
5 /opt/oracle/db02/oradata/ORCL/users01.dbf 0 Full 5226242 27-SEP-04
6 /opt/oracle/db02/oradata/ORCL/indx01.dbf 0 Full 5226242 27-SEP-04
7 /opt/oracle/db02/oradata/ORCL/drsys01.dbf 0 Full 5226242 27-SEP-04
10 /opt/oracle/db02/oradata/ORCL/test.dbf 0 Full 5226242 27-SEP-04
19 /opt/oracle/db02/oradata/ORCL/rbs02.dbf 0 Full 5226242 27-SEP-04
7.关闭数据库,模拟所有数据文件丢失,手工删除所有的数据文件、控制文件和联机日志文件:
$ lsnrctl stop
LSNRCTL for Solaris: Version 8.1.7.3.0 - Production on 27-SEP-2004 12:30:39
(c) Copyright 1998 Oracle Corporation. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ipasdb)(PORT=1521)))
The command completed successfully
$ sqlplus internal/oracle
SQL*Plus: Release 8.1.7.0.0 - Production on Mon Sep 27 12:29:12 2004
(c) Copyright 2000 Oracle Corporation. All rights reserved.
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.3.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.7.3.0 - 64bit Production
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
$ rm /opt/oracle/db02/oradata/ORCL/*
$ rm /opt/oracle/db03/oradata/ORCL/*
$ rm /opt/oracle/db04/oradata/ORCL/*
8.用rman做完全恢复:
(1).首先将数据库启动到nomount状态:
$ sqlplus internal/oracle
SQL*Plus: Release 8.1.7.0.0 - Production on Mon Sep 27 12:32:37 2004
(c) Copyright 2000 Oracle Corporation. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1134141116 bytes
Fixed Size 102076 bytes
Variable Size 311750656 bytes
Database Buffers 819200000 bytes
Redo Buffers 3088384 bytes
(2).做整个数据库恢复前,需要先恢复控制文件:
$ rman target / catalog rman/rman@rcat
Recovery Manager: Release 8.1.7.3.0 - Production
RMAN-06006: connected to target database: ORCL (not mounted)
RMAN-06008: connected to recovery catalog database
RMAN> run {
allocate channel c1 type disk;
restore controlfile;
release channel c1;
}
RMAN-03022: compiling command: allocate
RMAN-03023: executing command: allocate
RMAN-08030: allocated channel: c1
RMAN-08500: channel c1: sid=14 devtype=DISK
RMAN-03022: compiling command: restore
RMAN-03022: compiling command: IRESTORE
RMAN-03023: executing command: IRESTORE
RMAN-08016: channel c1: starting datafile backupset restore
RMAN-08502: set_count=3 set_stamp=537970127 creation_time=27-SEP-04
RMAN-08021: channel c1: restoring controlfile
RMAN-08505: output filename=/opt/oracle/db02/oradata/ORCL/control01.ctl
RMAN-08023: channel c1: restored backup piece 1
RMAN-08511: piece handle=/opt/oracle/full03g11hef_1_1 tag=DBFULL params=NULL
RMAN-08024: channel c1: restore complete
RMAN-08058: replicating controlfile
RMAN-08506: input filename=/opt/oracle/db02/oradata/ORCL/control01.ctl
RMAN-08505: output filename=/opt/oracle/db03/oradata/ORCL/control02.ctl
RMAN-08505: output filename=/opt/oracle/db04/oradata/ORCL/control03.ctl
RMAN-03022: compiling command: release
RMAN-03023: executing command: release
RMAN-08031: released channel: c1
(3).恢复归档日志文件:
RMAN> run {
set archivelog destination to '/opt/oracle/arch/ORCL';
allocate channel c1 type disk;
restore archivelog all;
release channel c1;
}
RMAN-03022: compiling command: set
RMAN-03022: compiling command: allocate
RMAN-03023: executing command: allocate
RMAN-08030: allocated channel: c1
RMAN-08500: channel c1: sid=14 devtype=DISK
RMAN-03022: compiling command: restore
RMAN-03022: compiling command: IRESTORE
RMAN-03023: executing command: IRESTORE
RMAN-08018: channel c1: starting archivelog restore to user-specified destination
RMAN-08508: archivelog destination=/opt/oracle/arch/ORCL
RMAN-08022: channel c1: restoring archivelog
RMAN-08510: archivelog thread=1 sequence=1
RMAN-08023: channel c1: restored backup piece 1
RMAN-08511: piece handle=/opt/oracle/db01/app/oracle/product/8.1.7/dbs/04g11hk1_1_1 tag=null params=NULL
RMAN-08024: channel c1: restore complete
RMAN-08018: channel c1: starting archivelog restore to user-specified destination
RMAN-08508: archivelog destination=/opt/oracle/arch/ORCL
RMAN-08022: channel c1: restoring archivelog
RMAN-08510: archivelog thread=1 sequence=2
RMAN-08022: channel c1: restoring archivelog
RMAN-08510: archivelog thread=1 sequence=3
RMAN-08022: channel c1: restoring archivelog
RMAN-08510: archivelog thread=1 sequence=4
RMAN-08023: channel c1: restored backup piece 1
RMAN-08511: piece handle=/opt/oracle/db01/app/oracle/product/8.1.7/dbs/05g11hk3_1_1 tag=null params=NULL
RMAN-08024: channel c1: restore complete
RMAN-03022: compiling command: release
RMAN-03023: executing command: release
RMAN-08031: released channel: c1
(4).恢复全部数据文件,并以resetlogs方式打开数据库:
RMAN> run {
allocate channel c1 type disk;
sql 'alter database mount';
restore database;
recover database;
sql 'alter database open resetlogs';
}
RMAN-03022: compiling command: allocate
RMAN-03023: executing command: allocate
RMAN-08030: allocated channel: c1
RMAN-08500: channel c1: sid=12 devtype=DISK
RMAN-03022: compiling command: sql
RMAN-06162: sql statement: alter database mount
RMAN-03023: executing command: sql
RMAN-03022: compiling command: restore
RMAN-03025: performing implicit partial resync of recovery catalog
RMAN-03023: executing command: partial resync
RMAN-08003: starting partial resync of recovery catalog
RMAN-08005: partial resync complete
RMAN-03022: compiling command: IRESTORE
RMAN-03023: executing command: IRESTORE
RMAN-08016: channel c1: starting datafile backupset restore
RMAN-08502: set_count=3 set_stamp=537970127 creation_time=27-SEP-04
RMAN-08089: channel c1: specifying datafile(s) to restore from backup set
RMAN-08523: restoring datafile 00001 to /opt/oracle/db02/oradata/ORCL/system01.dbf
RMAN-08523: restoring datafile 00002 to /opt/oracle/db02/oradata/ORCL/tools01.dbf
RMAN-08523: restoring datafile 00003 to /opt/oracle/db02/oradata/ORCL/rbs03.dbf
RMAN-08523: restoring datafile 00004 to /opt/oracle/db02/oradata/ORCL/temp01.dbf
RMAN-08523: restoring datafile 00005 to /opt/oracle/db02/oradata/ORCL/users01.dbf
RMAN-08523: restoring datafile 00006 to /opt/oracle/db02/oradata/ORCL/indx01.dbf
RMAN-08523: restoring datafile 00007 to /opt/oracle/db02/oradata/ORCL/drsys01.dbf
RMAN-08523: restoring datafile 00010 to /opt/oracle/db02/oradata/ORCL/test.dbf
RMAN-08523: restoring datafile 00019 to /opt/oracle/db02/oradata/ORCL/rbs02.dbf
RMAN-08023: channel c1: restored backup piece 1
RMAN-08511: piece handle=/opt/oracle/full03g11hef_1_1 tag=DBFULL params=NULL
RMAN-08024: channel c1: restore complete
RMAN-03023: executing command: partial resync
RMAN-08003: starting partial resync of recovery catalog
RMAN-08005: partial resync complete
RMAN-03022: compiling command: recover
RMAN-03022: compiling command: recover(1)
RMAN-03023: executing command: partial resync
RMAN-03022: compiling command: recover(2)
RMAN-03022: compiling command: recover(3)
RMAN-03023: executing command: recover(3)
RMAN-08054: starting media recovery
RMAN-03022: compiling command: recover(4)
RMAN-03023: executing command: recover(4)
RMAN-08017: channel c1: starting archivelog restore to default destination
RMAN-08022: channel c1: restoring archivelog
RMAN-08510: archivelog thread=1 sequence=4
RMAN-08023: channel c1: restored backup piece 1
RMAN-08511: piece handle=/opt/oracle/db01/app/oracle/product/8.1.7/dbs/05g11hk3_1_1 tag=null params=NULL
RMAN-08024: channel c1: restore complete
RMAN-08515: archivelog filename=/opt/oracle/arch/ORCL/arch_1_4.arc thread=1 sequence=4
RMAN-08060: unable to find archivelog
RMAN-08510: archivelog thread=1 sequence=5
RMAN-03026: error recovery releasing channel resources
RMAN-08031: released channel: c1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure during compilation of command
RMAN-03013: command type: recover
RMAN-03006: non-retryable error occurred during execution of command: recover(4)
RMAN-07004: unhandled exception during command execution on channel default
RMAN-20000: abnormal termination of job step
RMAN-06054: media recovery requesting unknown log: thread 1 scn 5226245
RMAN> exit
Recovery Manager complete.
发现有部分错误信息,分析原因主要是因为没有找到arch_1_5.arc归档日志的缘故,此时只能手工执行alter database open resetlogs打开数据库:
SQL> alter database open resetlogs;
Database altered.
注意:此时打开数据库后,可能会丢失部分数据,主要是当前redolog里的数据。因此上一步最后一个日志文件,应该用当前的redolog来恢复。
查看数据库的状态:
SQL> select status from v$instance;
STATUS
-------
OPEN
(5).恢复后rman数据库的同步:
$ rman target / catalog rman/rman@rcat
Recovery Manager: Release 8.1.7.3.0 - Production
RMAN-06005: connected to target database: ORCL (DBID=1000277484)
RMAN-06008: connected to recovery catalog database
RMAN> reset database;
RMAN-03022: compiling command: reset
RMAN-03023: executing command: reset
RMAN-08006: database registered in recovery catalog
RMAN-03023: executing command: full resync
RMAN-08002: starting full resync of recovery catalog
RMAN-08004: full resync complete
RMAN> exit
Recovery Manager complete.