本实验是在一个库中操作备份,然后删除三大文件,最后利用rman备份进行恢复数据库操作
1.开启归档、控制文件自动备份
SYS@PROD3> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/backup
Oldest online log sequence 1
Next log sequence to archive 2
Current log sequence 2
SYS@PROD3>
RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name PROD1 are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_PROD3.f'; # default
2.备份数据库
RMAN> backup as backupset database;
Starting backup at 22-DEC-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=43 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD3/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD3/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD3/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD3/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/PROD3/ts_setnew01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD3/users01.dbf
channel ORA_DISK_1: starting piece 1 at 22-DEC-16
channel ORA_DISK_1: finished piece 1 at 22-DEC-16
piece handle=/u01/app/oracle/fast_recovery_area/PROD1/backupset/2016_12_22/o1_mf_nnndf_TAG20161222T121403_d5pnrcy7_.bkp tag=TAG20161222T121403 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
Finished backup at 22-DEC-16
Starting Control File and SPFILE Autobackup at 22-DEC-16
piece handle=/u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_12_22/o1_mf_s_931263279_d5pnsh52_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 22-DEC-16
3.删除所有控制文件、数据文件、日志文件,以及参数文件
[oracle@enmo ~]$ cd /u01/app/oracle/oradata/PROD3
[oracle@enmo PROD3]$ ls
control01.ctl redo01.log redo03.log system01.dbf ts_setnew01.dbf users01.dbf
example01.dbf redo02.log sysaux01.dbf temp01.dbf undotbs01.dbf
[oracle@enmo PROD3]$ rm *
[oracle@enmo PROD3]$ cd /u01/app/oracle/fast_recovery_area/PROD3
[oracle@enmo PROD3]$ ls
control02.ctl
[oracle@enmo PROD3]$ rm control02.ctl
[oracle@enmo oradata]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs/
[oracle@enmo dbs]$ rm initPROD3.ora spfilePROD3.ora
4.修改实例名,启动到nomount
[oracle@enmo ~]$ echo $ORACLE_SID
PROD3
[oracle@enmo ~]$ export ORACLE_SID=PROD4
[oracle@enmo ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Dec 22 12:16:49 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN> startup 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/initPROD4.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 to '?/dbs/spfilePROD3.ora' from '/u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_12_22/o1_mf_s_931263279_d5pnsh52_.bkp';
Starting restore at 22-DEC-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/fast_recovery_area/PROD1/autobackup/2016_12_22/o1_mf_s_931263279_d5pnsh52_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 22-DEC-16
5.修改实例名,验证可以登录
[oracle@enmo oradata]$ export ORACLE_SID=PROD3
[oracle@enmo oradata]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 22 12:21:08 2016
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@PROD3> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /u01/app/oracle/product/11.2.0
/dbhome_1/dbs/spfilePROD3.ora
5.恢复控制文件
SYS@PROD3> shutdown abort;
ORACLE instance shut down.
SYS@PROD3> startup nomount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 520096848 bytes
Database Buffers 310378496 bytes
Redo Buffers 2371584 bytes
[oracle@enmo ~]$ export ORACLE_SID=PROD3
[oracle@enmo ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Dec 22 12:27:38 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD1 (not mounted)
RMAN> restore controlfile from '/u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_12_22/o1_mf_s_931263279_d5pnsh52_.bkp';
Starting restore at 22-DEC-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:01
output file name=/u01/app/oracle/oradata/PROD3/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/PROD3/control02.ctl
Finished restore at 22-DEC-16
启动数据库到mount状态
SYS@PROD3> alter database mount;
Database altered.
6.还原数据库
RMAN> restore database;
Starting restore at 22-DEC-16
released channel: ORA_DISK_1
Starting implicit crosscheck backup at 22-DEC-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
Crosschecked 5 objects
Finished implicit crosscheck backup at 22-DEC-16
Starting implicit crosscheck copy at 22-DEC-16
using channel ORA_DISK_1
Crosschecked 7 objects
Finished implicit crosscheck copy at 22-DEC-16
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_11_18/o1_mf_s_928259427_d2xmq3hr_.bkp
File Name: /u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_12_21/o1_mf_s_931197338_d5nndtr5_.bkp
File Name: /u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_11_29/o1_mf_s_929207478_d3tkkp7v_.bkp
File Name: /u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_11_29/o1_mf_s_929208145_d3tl6k2n_.bkp
File Name: /u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_12_22/o1_mf_s_931256068_d5pfr479_.bkp
File Name: /u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_12_22/o1_mf_s_931258749_d5pjcxjh_.bkp
File Name: /u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_12_22/o1_mf_s_931263279_d5pnsh52_.bkp
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/PROD3/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/PROD3/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/PROD3/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/PROD3/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/PROD3/example01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/PROD3/ts_setnew01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/PROD1/backupset/2016_12_22/o1_mf_nnndf_TAG20161222T121403_d5pnrcy7_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/PROD1/backupset/2016_12_22/o1_mf_nnndf_TAG20161222T121403_d5pnrcy7_.bkp tag=TAG20161222T121403
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 22-DEC-16
7.恢复数据库
RMAN> recover database;
Starting recover at 22-DEC-16
using channel ORA_DISK_1
starting media recovery
unable to find archived log
archived log thread=1 sequence=2
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 12/22/2016 12:33:33
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 2 and starting SCN of 1149490
此处我们会发现,在recover的时候,由于备份归档日志,所以,提示只能恢复到SCN 1149490
因为备份整库时只是备份到当时的点,而且用的是旧版的控制文件恢复数据库,所以只能恢复到旧版控制为文件记录的最新scn
SYS@PROD3> ed 002
run{
SET UNTIL SCN 1149490;
RESTORE DATABASE;
SWITCH DATAFILE ALL;
RECOVER DATABASE;
}
RMAN> run{
2> SET UNTIL SCN 1149490;
3> RESTORE DATABASE;
4> SWITCH DATAFILE ALL;
5> RECOVER DATABASE;
6> }
executing command: SET until clause
Starting restore at 22-DEC-16
using channel ORA_DISK_1
skipping datafile 1; already restored to file /u01/app/oracle/oradata/PROD3/system01.dbf
skipping datafile 2; already restored to file /u01/app/oracle/oradata/PROD3/sysaux01.dbf
skipping datafile 3; already restored to file /u01/app/oracle/oradata/PROD3/undotbs01.dbf
skipping datafile 4; already restored to file /u01/app/oracle/oradata/PROD3/users01.dbf
skipping datafile 5; already restored to file /u01/app/oracle/oradata/PROD3/example01.dbf
skipping datafile 6; already restored to file /u01/app/oracle/oradata/PROD3/ts_setnew01.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 22-DEC-16
Starting recover at 22-DEC-16
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 22-DEC-16
打开数据库
SYS@PROD3> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SYS@PROD3> alter database open resetlogs;
Database altered.
验证
SYS@PROD3> select status from v$instance;
STATUS
------------
OPEN
SYS@PROD3> show parameter name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string PROD1
db_unique_name string PROD1
global_names boolean FALSE
instance_name string PROD3
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string PROD1
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31400681/viewspace-2131209/
,如需转载,请注明出处,否则将追究法律责任。