【备份恢复】在 ARCHIVELOG 模式下执行数据库还原和恢复操作(源库备份源库恢复)...

ARCHIVELOG 模式下执行数据库还原和恢复操作

本实验是在一个库中操作备份,然后删除三大文件,最后利用rman备份进行恢复数据库操作

1.查看归档与否:

SYS@ORA11GR2>archive log list;

Database log mode              No Archive Mode

Automatic archival             Disabled

Archive destination            /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch

Oldest online log sequence     14

Current log sequence           16

SYS@ORA11GR2>show parameter recover

NAME                                 TYPE        VALUE

------------------------------------ -----------

db_recovery_file_dest                string

db_recovery_file_dest_size           big integer 0

db_unrecoverable_scn_tracking        boolean     TRUE

recovery_parallelism                 integer     0

SYS@ORA11GR2>

SYS@ORA11GR2>alter system set db_recovery_file_dest_size=3g;

 

System altered.

 

SYS@ORA11GR2>!mkdir -p /u01/app/FRA

 

SYS@ORA11GR2>alter system set db_recovery_file_dest='/u01/app/FRA';

 

System altered.

 

——设置归档为enable

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 archivelog;

 

Database altered.

 

SYS@ORA11GR2>archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     14

Next log sequence to archive   16

Current log sequence           16

SYS@ORA11GR2>alter database open;

 

Database altered.

 

2.RMAN自动备份控制文件功能开启:

(建议备份时也备份归档日志,以实现完全恢复,否则则需进行不完全恢复)

[oracle@wang ~]$ rman target /

 

Recovery Manager: Release 11.2.0.4.0 - Production on Sat Oct 8 14:44:58 2016

 

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

 

connected to target database: ORA11GR2 (DBID=237843809)

 

RMAN> show all;

 

using target database control file instead of recovery catalog

RMAN configuration parameters for database with db_unique_name ORA11GR2 are:

CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default

CONFIGURE BACKUP OPTIMIZATION OFF; # default

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default

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_ORA11GR2.f'; # default

 

RMAN> configure controlfile autobackup on;

 

new RMAN configuration parameters:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters are successfully stored

 

RMAN>

 

2.备份数据库:

RMAN> backup database;

 

Starting backup at 08-OCT-16

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=49 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/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/FRA/ORA11GR2/backupset/2016_10_08/o1_mf_nnndf_TAG20161008T144726_czk5n060_.bkp tag=TAG20161008T144726 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:56

Finished backup at 08-OCT-16

 

Starting Control File and SPFILE Autobackup at 08-OCT-16

piece handle=/u01/app/FRA/ORA11GR2/autobackup/2016_10_08/o1_mf_s_924706105_czk5otjm_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 08-OCT-16

 

3.删除所有控制文件、数据文件、日志文件,以及参数文件:

[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]$ cd $ORACLE_HOME/dbs

[oracle@wang dbs]$ ls spfileORA11GR2.ora initORA11GR2.ora

initORA11GR2.ora  spfileORA11GR2.ora

[oracle@wang dbs]$ rm spfileORA11GR2.ora initORA11GR2.ora

[oracle@wang dbs]$ ls spfileORA11GR2.ora initORA11GR2.ora

ls: spfileORA11GR2.ora: No such file or directory

ls: initORA11GR2.ora: No such file or directory

[oracle@wang dbs]$

 

4.执行恢复:

1)修改环境变量$ORACLE_SID

[oracle@wang ~]$ echo $ORACLE_SID

ORA11GR2

[oracle@wang ~]$ export ORACLE_SID=SF

[oracle@wang ~]$ echo $ORACLE_SID

SF

 

2)登录RMAN(可以在没有参数文件的情况下登录实例)

[oracle@wang ~]$ rman target /

 

Recovery Manager: Release 11.2.0.4.0 - Production on Sat Oct 8 14:56:11 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/initSF.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

 

3)恢复参数文件:

RMAN> restore spfile to '$ORACLE_HOME/dbs/spfileORA11GR2.ora' from '/u01/app/FRA/ORA11GR2/autobackup/2016_10_08/o1_mf_s_924706105_czk5otjm_.bkp';

 

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/FRA/ORA11GR2/autobackup/2016_10_08/o1_mf_s_924706105_czk5otjm_.bkp

channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete

Finished restore at 08-OCT-16

——验证:

[oracle@wang dbs]$ pwd

/u01/app/oracle/product/11.2.0/dbhome_1/dbs

[oracle@wang dbs]$ ls spfileORA11GR2.ora

spfileORA11GR2.ora

 

4)关闭实例及重新以恢复的参数文件(即ORA11GR2登录到实例:

[oracle@wang ~]$ echo $ORACLE_SID

SF

[oracle@wang ~]$ export ORACLE_SID=ORA11GR2

[oracle@wang ~]$ echo $ORACLE_SID

ORA11GR2

[oracle@wang ~]$

——验证可以登录到实例(以ORA11GR2

SYS@ORA11GR2>startup nomount;

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

SYS@ORA11GR2>

SYS@ORA11GR2>show parameter spfile

 

NAME                        TYPE           VALUE

------------------------------------ -----------

spfile string u01/app/oracle/product/11.2.0                                                 /dbhome_1/dbs/spfileORA11GR2.ora

 

5)继续以RMAN恢复控制文件(重储)

RMAN> restore controlfile from '/u01/app/FRA/ORA11GR2/autobackup/2016_10_08/o1_mf_s_924706105_czk5otjm_.bkp';

 

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=21 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;

 

database mounted

released channel: ORA_DISK_1

 

6)恢复数据库:(重储数据库)

RMAN> restore database;

 

Starting restore at 08-OCT-16

Starting implicit crosscheck backup at 08-OCT-16

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=18 device type=DISK

Crosschecked 1 objects

Finished implicit crosscheck backup at 08-OCT-16

 

Starting implicit crosscheck copy at 08-OCT-16

using channel ORA_DISK_1

Finished implicit crosscheck copy at 08-OCT-16

 

searching for all files in the recovery area

cataloging files...

cataloging done

 

List of Cataloged Files

=======================

File Name: /u01/app/FRA/ORA11GR2/autobackup/2016_10_08/o1_mf_s_924706105_czk5otjm_.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/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/FRA/ORA11GR2/backupset/2016_10_08/o1_mf_nnndf_TAG20161008T144726_czk5n060_.bkp

channel ORA_DISK_1: piece handle=/u01/app/FRA/ORA11GR2/backupset/2016_10_08/o1_mf_nnndf_TAG20161008T144726_czk5n060_.bkp tag=TAG20161008T144726

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:01:15

Finished restore at 08-OCT-16

 

7)恢复数据库(recover因为是热备数据库且处于归档模式)

RMAN> recover database;

 

Starting recover at 08-OCT-16

using channel ORA_DISK_1

 

starting media recovery

unable to find archived log

archived log thread=1 sequence=14

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 10/08/2016 15:26:39

RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 14 and starting SCN of 1201609

此处我们会发现,在recover的时候,由于备份归档日志,所以,提示只能恢复到SCN 1201609

因为备份库时只是备份到当时的点,而且用的是旧版的控制文件恢复数据库,所以只能恢复到旧版控制为文件记录的最新scn

——解决:

RMAN> run{                          

2>  SET UNTIL SCN 1201609;       

3>  RESTORE DATABASE;           

4>  SWITCH DATAFILE ALL;        

5>  RECOVER DATABASE;           

6>  }                           

 

executing command: SET until clause

 

Starting restore at 08-OCT-16

using channel ORA_DISK_1

 

skipping datafile 1; already restored to file /u01/app/oracle/oradata/ORA11GR2/system01.dbf

skipping datafile 2; already restored to file /u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf

skipping datafile 3; already restored to file /u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf

skipping datafile 4; already restored to file /u01/app/oracle/oradata/ORA11GR2/users01.dbf

skipping datafile 5; already restored to file /u01/app/oracle/oradata/ORA11GR2/example01.dbf

restore not done; all files read only, offline, or already restored

Finished restore at 08-OCT-16

 

 

Starting recover at 08-OCT-16

using channel ORA_DISK_1

 

starting media recovery

media recovery complete, elapsed time: 00:00:01

 

Finished recover at 08-OCT-16

 

——打开数据库:

RMAN> alter database open;

 

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of alter db command at 10/08/2016 15:32:17

ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

 

RMAN> alter database open resetlogs;(属于不完全恢复)

 

database opened

 

8)验证数据库恢复回来了:

SYS@ORA11GR2>select status from v$instance;

 

STATUS

------------

OPEN

 

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>!ls /u01/app/oracle/oradata/ORA11GR2/

control01.ctl  example01.dbf  redo02.log  sysaux01.dbf  temp01.dbf     users01.dbf

control02.ctl  redo01.log     redo03.log  system01.dbf  undotbs01.dbf

源库执行数据库还原和恢复操作完成!!!!!!!!!!!!


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31397003/viewspace-2126537/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31397003/viewspace-2126537/

你可能感兴趣的:(数据库)