SQL> conn / as sysdba
Connected.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/oracle/oradata/orcl/system01.dbf
/u01/oracle/oradata/orcl/sysaux01.dbf
/u01/oracle/oradata/orcl/undotbs01.dbf
/u01/oracle/oradata/orcl/users01.dbf
#创建测试表空间
SQL> create tablespace test1 datafile '/u01/oracle/oradata/orcl/test1_01.dbf' size 20M autoextend on next 1M maxsize unlimited;
Tablespace created.
SQL> create tablespace test2 datafile '/u01/oracle/oradata/orcl/test2_01.dbf' size 20M autoextend on next 1M maxsize unlimited;
Tablespace created.
#创建测试表并插入测试数据
SQL> conn scott/tiger
Connected.
SQL>
SQL> create table t1(id number) tablespace test1;
Table created.
SQL> create table t2(id number) tablespace test2;
Table created.
SQL> insert into t1 values(1);
1 row created.
SQL> insert into t1 values(2);
1 row created.
SQL> insert into t2 values(3);
1 row created.
SQL> insert into t2 values(4);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t1;
ID
----------
1
2
SQL> select * from t2;
ID
----------
3
4
SQL> conn scott/tiger
Connected.
SQL> select table_name from user_tables;
TABLE_NAME
------------------------------
T2
T1
SALGRADE
BONUS
EMP
DEPT
SQL> conn / as sysdba
Connected.
SQL>
SQL>
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 430112768 bytes
Fixed Size 2253864 bytes
Variable Size 373296088 bytes
Database Buffers 50331648 bytes
Redo Buffers 4231168 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
#备份数据库
run{
allocate channel a1 type disk;
crosscheck backup;
delete noprompt expired backup;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup as compressed backupset database format '/u01/rman/incr_%T_%d_%s_%p.bak';
sql 'alter system switch logfile';
backup as compressed backupset archivelog all format '/u01/rman/arc_%T_%d_%s_%p.bak' delete all input;
backup current controlfile format '/u01/rman/ctl_%T_%d_db_%s_%p.bak';
release channel a1;
}
[oracle@oratest dbs]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Tue Jul 19 17:15:12 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1445409661)
RMAN> run{
2> allocate channel a1 type disk;
3> crosscheck backup;
4> delete noprompt expired backup;
5> crosscheck archivelog all;
6> delete noprompt expired archivelog all;
7> backup as compressed backupset database format '/u01/rman/incr_%T_%d_%s_%p.bak';
8> sql 'alter system switch logfile';
9> backup as compressed backupset archivelog all format '/u01/rman/arc_%T_%d_%s_%p.bak' delete all input;
10> backup current controlfile format '/u01/rman/ctl_%T_%d_db_%s_%p.bak';
11> release channel a1;
12> }
released channel: ORA_DISK_1
allocated channel: a1
channel a1: SID=29 device type=DISK
specification does not match any backup in the repository
specification does not match any backup in the repository
specification does not match any archived log in the repository
specification does not match any archived log in the repository
Starting backup at 19-JUL-16
channel a1: starting compressed full datafile backup set
channel a1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/oracle/oradata/orcl/system01.dbf
input datafile file number=00002 name=/u01/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00003 name=/u01/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00005 name=/u01/oracle/oradata/orcl/test1_01.dbf
input datafile file number=00006 name=/u01/oracle/oradata/orcl/test2_01.dbf
input datafile file number=00004 name=/u01/oracle/oradata/orcl/users01.dbf
channel a1: starting piece 1 at 19-JUL-16
channel a1: finished piece 1 at 19-JUL-16
piece handle=/u01/rman/incr_20160719_ORCL_28_1.bak tag=TAG20160719T180457 comment=NONE
channel a1: backup set complete, elapsed time: 00:01:06
channel a1: starting compressed full datafile backup set
channel a1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel a1: starting piece 1 at 19-JUL-16
channel a1: finished piece 1 at 19-JUL-16
piece handle=/u01/rman/incr_20160719_ORCL_29_1.bak tag=TAG20160719T180457 comment=NONE
channel a1: backup set complete, elapsed time: 00:00:01
Finished backup at 19-JUL-16
sql statement: alter system switch logfile
Starting backup at 19-JUL-16
current log archived
channel a1: starting compressed archived log backup set
channel a1: specifying archived log(s) in backup set
input archived log thread=1 sequence=16 RECID=12 STAMP=917633167
input archived log thread=1 sequence=17 RECID=13 STAMP=917633167
channel a1: starting piece 1 at 19-JUL-16
channel a1: finished piece 1 at 19-JUL-16
piece handle=/u01/rman/arc_20160719_ORCL_30_1.bak tag=TAG20160719T180607 comment=NONE
channel a1: backup set complete, elapsed time: 00:00:01
channel a1: deleting archived log(s)
archived log file name=/u01/oracle/fast_recovery_area/ORCL/archivelog/2016_07_19/o1_mf_1_16_crvywgmc_.arc RECID=12 STAMP=917633167
archived log file name=/u01/oracle/fast_recovery_area/ORCL/archivelog/2016_07_19/o1_mf_1_17_crvywhn4_.arc RECID=13 STAMP=917633167
Finished backup at 19-JUL-16
Starting backup at 19-JUL-16
channel a1: starting full datafile backup set
channel a1: specifying datafile(s) in backup set
including current control file in backup set
channel a1: starting piece 1 at 19-JUL-16
channel a1: finished piece 1 at 19-JUL-16
piece handle=/u01/rman/ctl_20160719_ORCL_db_31_1.bak tag=TAG20160719T180609 comment=NONE
channel a1: backup set complete, elapsed time: 00:00:01
Finished backup at 19-JUL-16
released channel: a1
#恢复数据库
#异机通过pfile文件启动数据库并恢复控制文件,使数据库进入mount状态
SQL> startup mount
ORACLE instance started.
Total System Global Area 430112768 bytes
Fixed Size 2253864 bytes
Variable Size 373296088 bytes
Database Buffers 50331648 bytes
Redo Buffers 4231168 bytes
Database mounted.
SQL>
[oracle@oratest ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Tue Jul 19 18:08:42 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (not mounted)
RMAN> restore controlfile from '/u01/rman/ctl_20160719_ORCL_db_31_1.bak';
Starting restore at 19-JUL-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u01/oracle/oradata/orcl/control01.ctl
output file name=/u01/oracle/fast_recovery_area/orcl/control02.ctl
Finished restore at 19-JUL-16
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN> catalog start with '/u01/rman';
Starting implicit crosscheck backup at 20-JUL-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
Crosschecked 3 objects
Finished implicit crosscheck backup at 20-JUL-16
Starting implicit crosscheck copy at 20-JUL-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 20-JUL-16
searching for all files in the recovery area
cataloging files...
no files cataloged
searching for all files that match the pattern /u01/rman
List of Files Unknown to the Database
=====================================
File Name: /u01/rman/ctl_20160719_ORCL_db_31_1.bak
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/rman/ctl_20160719_ORCL_db_31_1.bak
#通过restore database skip tablespace命令还原数据文件,忽略掉不需要的表空间
RMAN> restore database skip tablespace TEST2;
Starting restore at 20-JUL-16
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 /u01/oracle/oradata/orcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/oracle/oradata/orcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/oracle/oradata/orcl/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/oracle/oradata/orcl/test1_01.dbf
channel ORA_DISK_1: reading from backup piece /u01/rman/incr_20160719_ORCL_28_1.bak
channel ORA_DISK_1: piece handle=/u01/rman/incr_20160719_ORCL_28_1.bak tag=TAG20160719T180457
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
Finished restore at 20-JUL-16
#通过recover database skip tablespace命令恢复数据,忽略掉不需要的表空间
RMAN> recover database skip tablespace TEST2;
Starting recover at 20-JUL-16
using channel ORA_DISK_1
Executing: alter database datafile 6 offline
starting media recovery
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=16
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=17
channel ORA_DISK_1: reading from backup piece /u01/rman/arc_20160719_ORCL_30_1.bak
channel ORA_DISK_1: piece handle=/u01/rman/arc_20160719_ORCL_30_1.bak tag=TAG20160719T180607
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
archived log file name=/u01/oracle/fast_recovery_area/ORCL/archivelog/2016_07_20/o1_mf_1_16_crxqy7b3_.arc thread=1 sequence=16
channel default: deleting archived log(s)
archived log file name=/u01/oracle/fast_recovery_area/ORCL/archivelog/2016_07_20/o1_mf_1_16_crxqy7b3_.arc RECID=15 STAMP=917691592
archived log file name=/u01/oracle/fast_recovery_area/ORCL/archivelog/2016_07_20/o1_mf_1_17_crxqy7g2_.arc thread=1 sequence=17
channel default: deleting archived log(s)
archived log file name=/u01/oracle/fast_recovery_area/ORCL/archivelog/2016_07_20/o1_mf_1_17_crxqy7g2_.arc RECID=14 STAMP=917691591
unable to find archived log
archived log thread=1 sequence=18
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/20/2016 10:19:55
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 18 and starting SCN of 991122
#通过open resetlogs打开数据库
SQL> conn / as sysdba
Connected.
SQL>
SQL>
SQL> alter database open resetlogs;
Database altered.
#检查结果
SQL> select name from v$tablespace;
NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
USERS
TEMP
TEST1
TEST2
7 rows selected.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/oracle/oradata/orcl/system01.dbf
/u01/oracle/oradata/orcl/sysaux01.dbf
/u01/oracle/oradata/orcl/undotbs01.dbf
/u01/oracle/oradata/orcl/users01.dbf
/u01/oracle/oradata/orcl/test1_01.dbf
/u01/oracle/oradata/orcl/test2_01.dbf
6 rows selected.
SQL> conn scott/tiger
Connected.
SQL>
SQL> select * from t1;
ID
----------
1
2
SQL> select * from t2;
select * from t2
*
ERROR at line 1:
ORA-00376: file 6 cannot be read at this time
ORA-01110: data file 6: '/u01/oracle/oradata/orcl/test2_01.dbf'
[root@oratest ~]# ls /u01/oracle/oradata/orcl/
control01.ctl redo01.log redo02.log redo03.log sysaux01.dbf system01.dbf temp01.dbf test1_01.dbf undotbs01.dbf users01.dbf