---撤销数据库archivelog模式
sys@PROD>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@PROD>
sys@PROD>startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 507513936 bytes
Database Buffers 322961408 bytes
Redo Buffers 2371584 bytes
Database mounted.
sys@PROD>alter database noarchivelog;
Database altered.
--查看数据库的归档模式:
sys@PROD>archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Current log sequence 1
sys@PROD>
---创建测试表:
sys@PROD>alter database open;
Database altered.
--插入第一条数据:
sys@PROD>create table t(x int) tablespace users;
Table created.
---在noarchivelog模式下,0级备份:
run{
shutdown immediate;
startup mount;
backup as backupset incremental level 0 database;
alter database open;
}
#这是草稿#
[oracle@enmo ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Nov 7 17:57:54 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=338469376)
RMAN> run{
2> shutdown immediate;
3> startup mount;
4> backup as backupset incremental level 0 database;
5> alter database open;
6> }
using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 507513936 bytes
Database Buffers 322961408 bytes
Redo Buffers 2371584 bytes
Starting backup at 07-NOV-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 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/PROD/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/PROD/ts_xxf_01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/users01.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/PROD/ts_ctl01.dbf
channel ORA_DISK_1: starting piece 1 at 07-NOV-16
channel ORA_DISK_1: finished piece 1 at 07-NOV-16
piece handle=/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_nnnd0_TAG20161107T175851_d20n2vry_.bkp tag=TAG20161107T175851 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:03:52
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 07-NOV-16
channel ORA_DISK_1: finished piece 1 at 07-NOV-16
piece handle=/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_ncsn0_TAG20161107T175851_d20nb469_.bkp tag=TAG20161107T175851 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 07-NOV-16
--插入第二条数据:
sys@PROD>conn / as sysdba
Connected.
sys@PROD>
sys@PROD>insert into t values(2);
1 row created.
sys@PROD>commit;
Commit complete.
--在noarchivelog模式下,1级备份:
[oracle@enmo ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Nov 7 18:06:37 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=338469376)
RMAN> run{
2> shutdown immediate;
3> startup mount;
4> backup as backupset incremental level 1 database;
5> alter database open;
6> }
using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 507513936 bytes
Database Buffers 322961408 bytes
Redo Buffers 2371584 bytes
Starting backup at 07-NOV-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/PROD/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/PROD/ts_xxf_01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/users01.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/PROD/ts_ctl01.dbf
channel ORA_DISK_1: starting piece 1 at 07-NOV-16
channel ORA_DISK_1: finished piece 1 at 07-NOV-16
piece handle=/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_nnnd1_TAG20161107T180734_d20nm6l6_.bkp tag=TAG20161107T180734 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:55
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 07-NOV-16
channel ORA_DISK_1: finished piece 1 at 07-NOV-16
piece handle=/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_ncsn1_TAG20161107T180734_d20npwpw_.bkp tag=TAG20161107T180734 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-NOV-16
database opened
#1级增量备份完成。
---删除所有控制文件、日志文件、数据文件、参数文件:
--删除控制文件:
sys@PROD>!rm /u01/app/oracle/oradata/PROD/control01.ctl
sys@PROD>!rm /u01/app/oracle/fast_recovery_area/PROD/control02.ctl
--删除日志文件与数据文件:
[oracle@enmo ~]$ cd /u01/app/oracle/oradata/PROD/
[oracle@enmo PROD]$ ls
example01.dbf redo02.log sysaux01.dbf temp01.dbf ts_xxf_01.dbf users01.dbf
redo01.log redo03.log system01.dbf ts_ctl01.dbf undotbs01.dbf
[oracle@enmo PROD]$ rm *
--删除参数文件:
[oracle@enmo ~]$ cd $ORACLE_HOME/dbs
[oracle@enmo dbs]$ ls
hc_PROD.dat init.ora lkPROD orapwPROD PROD.ora.bck snapcf_PROD.f spfilePROD.ora
[oracle@enmo dbs]$
[oracle@enmo dbs]$ rm PROD.ora.bck
[oracle@enmo dbs]$ cp spfilePROD.ora PROD.ora.bck
[oracle@enmo dbs]$ rm spfilePROD.ora
[oracle@enmo dbs]$ ls
hc_PROD.dat init.ora lkPROD orapwPROD PROD.ora.bck snapcf_PROD.f
[oracle@enmo dbs]$
---执行恢复:
--强制打开到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/initPROD.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/FRA/PROD/backupset/2016_11_07/o1_mf_ncsn1_TAG20161107T180734_d20npwpw_.bkp";
Starting restore at 07-NOV-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/FRA/PROD/backupset/2016_11_07/o1_mf_ncsn1_TAG20161107T180734_d20npwpw_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 07-NOV-16
[oracle@enmo dbs]$ ls spfile*
spfilePROD.ora
[oracle@enmo dbs]$
#参数恢复完成。
--恢复控制文件:
--完成参数文件的恢复,利用恢复的参数文件启动到nomount模式:
RMAN> shutdown abort;
Oracle instance shut down
RMAN>
--再次启动nomount状态:
RMAN> startup nomount;
connected to target database (not started)
Oracle instance started
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 507513936 bytes
Database Buffers 322961408 bytes
Redo Buffers 2371584 bytes
restore controlfile from "/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_ncsn1_TAG20161107T180734_d20npwpw_.bkp";
--恢复控制文件:
RMAN> restore controlfile from "/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_ncsn1_TAG20161107T180734_d20npwpw_.bkp";
Starting restore at 07-NOV-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:03
output file name=/u01/app/oracle/oradata/PROD/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/PROD/control02.ctl
Finished restore at 07-NOV-16
#以上的参数文件与控制文件都是从最新的自动备份文件恢复。
---控制文件恢复完成,数据库启动到mount模式:
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
---执行全库的还原:
RMAN> restore database;
Starting restore at 07-NOV-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/app/oracle/oradata/PROD/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/PROD/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/PROD/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/PROD/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/PROD/example01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/PROD/ts_xxf_01.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/PROD/ts_ctl01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_nnnd0_TAG20161107T175851_d20n2vry_.bkp
channel ORA_DISK_1: piece handle=/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_nnnd0_TAG20161107T175851_d20n2vry_.bkp tag=TAG20161107T175851
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:03:05
Finished restore at 07-NOV-16
---恢复数据库,由于是非归档模式所以使用无日志恢复方式:
RMAN> recover database noredo;
Starting recover at 07-NOV-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/PROD/system01.dbf
destination for restore of datafile 00002: /u01/app/oracle/oradata/PROD/sysaux01.dbf
destination for restore of datafile 00003: /u01/app/oracle/oradata/PROD/undotbs01.dbf
destination for restore of datafile 00004: /u01/app/oracle/oradata/PROD/users01.dbf
destination for restore of datafile 00005: /u01/app/oracle/oradata/PROD/example01.dbf
destination for restore of datafile 00006: /u01/app/oracle/oradata/PROD/ts_xxf_01.dbf
destination for restore of datafile 00007: /u01/app/oracle/oradata/PROD/ts_ctl01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_nnnd1_TAG20161107T180734_d20nm6l6_.bkp
channel ORA_DISK_1: piece handle=/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_nnnd1_TAG20161107T180734_d20nm6l6_.bkp tag=TAG20161107T180734
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished recover at 07-NOV-16
---恢复完成,resetlogs方式打开数据库,完成所有文件丢失的恢复:
RMAN> alter database open resetlogs;
database opened
#已完成恢复并成功打开数据库。
---恢复后,查看t表的数据是否丢失:
sys@PROD>select * from t;
X
----------
1
2
#非归档模式下恢复成功,使用两个两级(0级备份与1级增量备份)的备份完成了完全恢复。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31392094/viewspace-2128011/ ,如需转载,请注明出处,否则将追究法律责任。