基于scn号恢复oracle数据库测试

oracle11g 数据库 

RMAN> backup database plus archivelog delete all input; (首先做一次数据库全备)

[oracle@linux ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Jul 16 16:52:01 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@testdb> conn scott/oracle 连接到数据库scott用户,新建一张表格
Connected.
SCOTT@testdb> create table t1 (x int);
Table created.
SCOTT@testdb> insert into t1 values (1);
1 row created.
SCOTT@testdb> commit ; (表格中插入数据,提交
Commit complete.
SCOTT@testdb> select * from t1;
X
----------
1
SCOTT@testdb> conn / as sysdba
Connected.
SYS@testdb> select timestamp_to_scn(sysdate) from v$database; 查看当前状态的SCN号
TIMESTAMP_TO_SCN(SYSDATE)
-------------------------
1026157
SYS@testdb>
SYS@testdb> conn scott/oracle
Connected.
SCOTT@testdb> insert into t1 values (2);
1 row created.
SCOTT@testdb> commit ;
Commit complete.
SCOTT@testdb> select * from t1;
X
----------
1
2
SCOTT@testdb> conn / as sysdba
Connected.
SYS@testdb> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@testdb> startup mount;
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 1006636192 bytes
Database Buffers 587202560 bytes
Redo Buffers 7319552 bytes
Database mounted.
SYS@testdb>
SYS@testdb> quit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@linux ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Jul 16 16:58:23 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: TESTDB (DBID=2764677489, not open)
RMAN> run{ (基于SCN号恢复数据库到scn所指状态)
2> set until scn = 1026157;
3> restore database;
4> recover database;
5> alter database open resetlogs;
6> }
executing command: SET until clause
Starting restore at 2018-07-16 16:59:43
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=63 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 /u01/app/oracle/oradata/TESTDB/datafile/o1_mf_system_fnhjdl8q_.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/TESTDB/datafile/o1_mf_sysaux_fnhjdl9x_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/TESTDB/datafile/o1_mf_undotbs1_fnhjdlb1_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/TESTDB/datafile/o1_mf_users_fnhjdlbo_.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/TESTDB/datafile/o1_mf_example_fnhjj8l9_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/TESTDB/backupset/2018_07_16/o1_mf_nnndf_TAG20180716T164512_fnrprryw_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/TESTDB/backupset/2018_07_16/o1_mf_nnndf_TAG20180716T164512_fnrprryw_.bkp tag=TAG20180716T164512
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:06
Finished restore at 2018-07-16 17:01:50
Starting recover at 2018-07-16 17:01:50
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:02
Finished recover at 2018-07-16 17:01:52
database opened
RMAN>
RMAN> quit
Recovery Manager complete.
[oracle@linux ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Jul 16 17:05:00 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@testdb> conn scott/oracle
Connected.
SCOTT@testdb> select * from t1; (查看,已经恢复)
X
----------
1
SCOTT@testdb>
SCOTT@testdb> conn / as sysdba
Connected.
SYS@testdb> select timestamp_to_scn(sysdate) from v$database;
TIMESTAMP_TO_SCN(SYSDATE)
-------------------------
1026598
SYS@testdb>
原文地址:https://www.cnblogs.com/Chaos-oaa/p/9548381.html