使用增量备份恢复处于NOARCHIVELOG 模式的数据库
增量备份前提是有0即全库备份,另外默认的增量备份是指增量差异备份(backup as backupset incremental level 1database),如果要改为增量累计备份还需要加命令cumulative。
1.撤销数据库archivelog模式
SYS@ORA11GR2>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@ORA11GR2>
SYS@ORA11GR2>startup mount;
ORACLE instance started.
Total System Global Area 830930944 bytes
Fixed Size 2257800 bytes
Variable Size 503319672 bytes
Database Buffers 322961408 bytes
Redo Buffers 2392064 bytes
Database mounted.
SYS@ORA11GR2>
SYS@ORA11GR2>alter database noarchivelog;
Database altered.
SYS@ORA11GR2>archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 3
Current log sequence 5
SYS@ORA11GR2>alter database open;
Database altered.
2.创建测试用表及数据
SYS@ORA11GR2>conn scott/tiger
Connected.
SCOTT@ORA11GR2>create table t(x int) tablespace users;
Table created.
SCOTT@ORA11GR2>insert into t values(1);
1 row created.
SCOTT@ORA11GR2>commit;
Commit complete.
3.在noarchivelog模式下,0级备份
[oracle@wang ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Sat Oct 8 12:47:03 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORA11GR2 (DBID=237843809)
RMAN> shutdown immediate;
using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down
RMAN> startup mount;
(RMAN备份,位于mount下是将备份信息记录在控制文件里,控制文件资料档案库)
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 730714112 bytes
Fixed Size 2256832 bytes
Variable Size 402653248 bytes
Database Buffers 322961408 bytes
Redo Buffers 2842624 bytes
——执行0级增量备份(默认是以备份集形式备份的)
RMAN> backup as backupset incremental level 0 database;
Starting backup at 08-OCT-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/ORA11GR2/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/ORA11GR2/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/ORA11GR2/users01.dbf
channel ORA_DISK_1: starting piece 1 at 08-OCT-16
channel ORA_DISK_1: finished piece 1 at 08-OCT-16
piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/01rhria3_1_1 tag=TAG20161008T124903 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:36
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 08-OCT-16
channel ORA_DISK_1: finished piece 1 at 08-OCT-16
piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/02rhrid4_1_1 tag=TAG20161008T124903 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 08-OCT-16
——启库:
RMAN> alter database open;
database opened
4.执行操作:
SCOTT@ORA11GR2>insert into t values(2);
1 row created.
SCOTT@ORA11GR2>commit;
Commit complete.
5.在noarchivelog模式下,1级备份
RMAN> run{
2> shutdown immediate;
3> startup mount;
4> backup as backupset incremental level 1 database;
5> alter database open;
6> }
database closed
database dismounted
Oracle instance shut down
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 730714112 bytes
Fixed Size 2256832 bytes
Variable Size 402653248 bytes
Database Buffers 322961408 bytes
Redo Buffers 2842624 bytes
Starting backup at 08-OCT-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/ORA11GR2/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/ORA11GR2/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/ORA11GR2/users01.dbf
channel ORA_DISK_1: starting piece 1 at 08-OCT-16
channel ORA_DISK_1: finished piece 1 at 08-OCT-16
piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/03rhriha_1_1 tag=TAG20161008T125257 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 08-OCT-16
channel ORA_DISK_1: finished piece 1 at 08-OCT-16
piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/04rhriie_1_1 tag=TAG20161008T125257 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 08-OCT-16
database opened
6.删除所有控制文件、日志文件、数据文件、参数文件
[oracle@wang ~]$ cd /u01/app/oracle/oradata/ORA11GR2
[oracle@wang ORA11GR2]$ ls
control01.ctl redo01.log sysaux01.dbf undotbs01.dbf
control02.ctl redo02.log system01.dbf users01.dbf
example01.dbf redo03.log temp01.dbf
[oracle@wang ORA11GR2]$ rm *
[oracle@wang ORA11GR2]$ ls
[oracle@wang ORA11GR2]$
[oracle@wang ORA11GR2]$ cd $ORACLE_HOME/dbs
[oracle@wang dbs]$ ls spfileORA11GR2.ora
spfileORA11GR2.ora
[oracle@wang dbs]$ rm spfileORA11GR2.ora
[oracle@wang dbs]$ ls spfileORA11GR2.ora
ls: spfileORA11GR2.ora: No such file or directory
[oracle@wang dbs]$
7.执行恢复
[oracle@wang dbs]$ echo $ORACLE_SID
ORA11GR2
[oracle@wang dbs]$ export ORACLE_SID=ORA
[oracle@wang dbs]$ echo $ORACLE_SID
ORA
[[oracle@wang dbs]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Sat Oct 8 12:57:29 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
--强制启动到nomount模式(rman优势,即在无参数文件状态下可以启动到nomount)
RMAN> startup force nomount;
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initORA.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 281019272 bytes
Database Buffers 780140544 bytes
Redo Buffers 5517312 bytes
--恢复参数文件,最好使用最后一次增量备份的备份介质
RMAN> restore spfile from '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/04rhriie_1_1';
Starting restore at 08-OCT-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/product/11.2.0/dbhome_1/dbs/04rhriie_1_1
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 08-OCT-16
--完成参数文件的恢复,利用恢复的参数文件启动到nomount模式
RMAN> shutdown abort
Oracle instance shut down
RMAN> startup nomount;
(打开实例)
connected to target database (not started)
Oracle instance started
Total System Global Area 730714112 bytes
Fixed Size 2256832 bytes
Variable Size 482345024 bytes
Database Buffers 243269632 bytes
Redo Buffers 2842624 bytes
--恢复控制文件,注意:此处恢复控制文件,一定要使用最后一次增量备份的备份介质,否则会因为版本的问题导致恢复出现问题
RMAN> restore controlfile from '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/04rhriie_1_1';
Starting restore at 08-OCT-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/ORA11GR2/control01.ctl
output file name=/u01/app/oracle/oradata/ORA11GR2/control02.ctl
Finished restore at 08-OCT-16
--控制文件恢复完成,数据库启动到mount模式
RMAN> alter database mount;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 10/08/2016 13:04:48
ORA-01102: cannot mount database in EXCLUSIVE mode
——解决:
[oracle@wang ~]$ ps -ef |grep ORA11GR2|awk '{print $2}' | xargs kill -9
kill 30985: No such process
[oracle@wang ~]$
——再次启动数据库到mount:
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
--执行全库的还原
RMAN> restore database;
Starting restore at 08-OCT-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 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/ORA11GR2/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/ORA11GR2/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/ORA11GR2/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/product/11.2.0/dbhome_1/dbs/01rhria3_1_1
channel ORA_DISK_1: piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/01rhria3_1_1 tag=TAG20161008T124903
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 08-OCT-16
--由于非归档,且联机重做日志丢失,所以使用noredo子句进行恢复
RMAN> recover database noredo;
Starting recover at 08-OCT-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /u01/app/oracle/oradata/ORA11GR2/system01.dbf
destination for restore of datafile 00002: /u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
destination for restore of datafile 00003: /u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
destination for restore of datafile 00004: /u01/app/oracle/oradata/ORA11GR2/users01.dbf
destination for restore of datafile 00005: /u01/app/oracle/oradata/ORA11GR2/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/product/11.2.0/dbhome_1/dbs/03rhriha_1_1
channel ORA_DISK_1: piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/03rhriha_1_1 tag=TAG20161008T125257
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished recover at 08-OCT-16
--恢复完成,resetlogs方式打开数据库,完成所有文件丢失的恢复
RMAN> alter database open resetlogs;
database opened
8.验证在测试前(增量备份前)插入的数据
——先将spfile改名:
[oracle@wang ~]$ echo $ORACLE_SID
ORA11GR2
[oracle@wang ~]$ cd $ORACLE_HOME/dbs
[oracle@wang dbs]$ ls
hc_ORA11GR2.dat lkORA11GR2
hc_ORA.dat orapwORA11GR2
init.ora snapcf_ORA11GR2.f
initORA11GR2.ora spfileORA.ora
[oracle@wang dbs]$
[oracle@wang dbs]$ mv spfileORA.ora spfileORA11GR2.ora
[oracle@wang dbs]$ ls spfileORA11GR2.ora
spfileORA11GR2.ora
[oracle@wang dbs]$ ls spfileORA.ora
ls: spfileORA.ora: No such file or directory
——连接到数据库:
[oracle@wang dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sat Oct 8 13:19:49 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SYS@ORA11GR2>startup
ORACLE instance started.
Total System Global Area 730714112 bytes
Fixed Size 2256832 bytes
Variable Size 402653248 bytes
Database Buffers 322961408 bytes
Redo Buffers 2842624 bytes
ORA-01102: cannot mount database in EXCLUSIVE mode
——解决:
[oracle@wang dbs]$ ps -ef |grep ORA|awk '{print $2}' | xargs kill -9
kill 31795: No such process
[oracle@wang dbs]$
——再次启库:
[oracle@wang dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sat Oct 8 13:22:01 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SYS@ORA11GR2>startup
ORACLE instance started.
Total System Global Area 730714112 bytes
Fixed Size 2256832 bytes
Variable Size 402653248 bytes
Database Buffers 322961408 bytes
Redo Buffers 2842624 bytes
Database mounted.
Database opened.
SYS@ORA11GR2>
——验证:
SYS@ORA11GR2>show parameter name
NAME TYPE VALUE
------------------------------------ -----------
cell_offloadgroup_name string
db_file_name_convert string
db_name string ORA11GR2
db_unique_name string ORA11GR2
global_names boolean FALSE
instance_name string ORA11GR2
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string ORA11GR2
SYS@ORA11GR2>
SYS@ORA11GR2>conn scott/tiger
Connected.
SCOTT@ORA11GR2>select * from t;
X
----------
1
2
验证数据都回来!!!!!!!!!!!!!
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31397003/viewspace-2126550/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31397003/viewspace-2126550/