Oracle 备份恢复实例

Oracle 备份恢复实例:三思笔记

 

1 shutdown abort

系统归档模式,有备份

create table xx as

select * from emp;

 

update xx set ename ='xxxxxx';

select * from xx

[oracle@localhost ~]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Wed Mar 19 14:13:27 2014

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL> conn /as sysdba

Connected.

SQL> shutdown abort;

ORACLE instance shut down.

SQL> startup;---启动需要实例恢复

ORACLE instance started.

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              79693392 bytes

Database Buffers          201326592 bytes

Redo Buffers                2973696 bytes

Database mounted.

Database opened.

--更新了未提交的数据,重新open后,被回滚

2 shutdown immediateundo丢失

 

update xx set ename ='xxxxxx';

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

[oracle@localhost grs]$ mv undotbs01.dbf /u01/oracle/backup/

SQL> startup;

ORACLE instance started.

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              79693392 bytes

Database Buffers          201326592 bytes

Redo Buffers                2973696 bytes

Database mounted.

ORA-01157: cannot identify/lock data file 2 - see DBWR trace file

ORA-01110: data file 2: '/u01/app/oracle/oradata/grs/undotbs01.dbf'

[oracle@localhost grs]$ rman target/

Recovery Manager: Release 10.2.0.1.0 - Production on Wed Mar 19 14:38:53 2014

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database: GRS (DBID=325518186, not open)

RMAN> restore datafile 2;

Starting restore at 19-MAR-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=155 devtype=DISK

 

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00002 to /u01/app/oracle/oradata/grs/undotbs01.dbf

channel ORA_DISK_1: reading from backup piece /u01/oracle/backup/rman1104_backup_1tp3gc5t_1_1

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/oracle/backup/rman1104_backup_1tp3gc5t_1_1 tag=TAG20140318T154813

channel ORA_DISK_1: restore complete, elapsed time: 00:00:36

Finished restore at 19-MAR-14

RMAN> recover datafile 2;

Starting recover at 19-MAR-14

using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 61 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_61_830623455.dbf

archive log thread 1 sequence 62 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_62_830623455.dbf

channel ORA_DISK_1: starting archive log restore to default destination

channel ORA_DISK_1: restoring archive log

archive log thread=1 sequence=60

channel ORA_DISK_1: reading from backup piece /u01/oracle/backup/rman1104_backup_1up3gc8s_1_1

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/oracle/backup/rman1104_backup_1up3gc8s_1_1 tag=TAG20140318T154948

channel ORA_DISK_1: restore complete, elapsed time: 00:00:02

archive log filename=/u01/app/oracle/archivelog/archivelog/1_60_830623455.dbf thread=1 sequence=60

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

Finished recover at 19-MAR-14

RMAN> alter database open;

database opened

RMAN>

 

 

3 undo丢失,有备份

[oracle@localhost grs]$ rm undotbs01.dbf

SQL> shutdown immediate;

ORA-01116: error in opening database file 2

ORA-01110: data file 2: '/u01/app/oracle/oradata/grs/undotbs01.dbf'

ORA-27041: unable to open file

Linux Error: 2: No such file or directory

Additional information: 3

SQL> shutdown abort;

ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

RMAN> restore datafile 2;

 

Starting restore at 19-MAR-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=155 devtype=DISK

 

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00002 to /u01/app/oracle/oradata/grs/undotbs01.dbf

channel ORA_DISK_1: reading from backup piece /u01/oracle/backup/rman1104_backup_1tp3gc5t_1_1

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/oracle/backup/rman1104_backup_1tp3gc5t_1_1 tag=TAG20140318T154813

channel ORA_DISK_1: restore complete, elapsed time: 00:00:36

Finished restore at 19-MAR-14

 

RMAN> recover datafile 2;

 

Starting recover at 19-MAR-14

using channel ORA_DISK_1

 

starting media recovery

 

archive log thread 1 sequence 60 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_60_830623455.dbf

archive log thread 1 sequence 61 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_61_830623455.dbf

archive log thread 1 sequence 62 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_62_830623455.dbf

archive log filename=/u01/app/oracle/archivelog/archivelog/1_60_830623455.dbf thread=1 sequence=60

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

Finished recover at 19-MAR-14

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              71304784 bytes

Database Buffers          209715200 bytes

Redo Buffers                2973696 bytes

Database mounted.

 

SQL> alter database datafile 2 offline drop;

 

Database altered.

 

SQL> alter database open;

 

Database altered.

 

SQL> alter database datafile 2 online;

 

Database altered.

 

4 shutdown abort,无备份,undo丢失

update xx set ename ='xxxxxx';

select s.sid,s.serial#,t.used_ublk,r.status,s.username,r.segment_name

from gv$transaction t, gv$session s, dba_rollback_segs r

where t.ses_addr = s.saddr and t.xidusn = r.segment_id and r.tablespace_name='UNDOTBS1';

 

144    5    1    ONLINE    SCOTT    _SYSSMU11$

 

SQL> shutdown abort;

ORACLE instance shut down.

[oracle@localhost grs]$ mv undotbs01.dbf /u01/oracle/backup/

SQL> startup;

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              71304784 bytes

Database Buffers          209715200 bytes

Redo Buffers                2973696 bytes

Database mounted.

ORA-01157: cannot identify/lock data file 2 - see DBWR trace file

ORA-01110: data file 2: '/u01/app/oracle/oradata/grs/undotbs01.dbf'

SQL> col error format a15

SQL> set linesize 1000

SQL> set pagesize 1000

SQL> select * from v$recover_file;--查看那个文件需要恢复

 

     FILE# ONLINE  ONLINE_ ERROR              CHANGE# TIME

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

         2 ONLINE  ONLINE  FILE NOT FOUND           0

SQL> alter database datafile 2 offline drop;

---设置为offline并删除(逻辑上)

Database altered.

SQL> alter database open;

--db可以打开

Database altered.

SQL> conn        

Enter user-name: scott

Enter password:

Connected.

SQL> select * from xx;

select * from xx

              *

ERROR at line 1:

ORA-00376: file 2 cannot be read at this time

ORA-01110: data file 2: '/u01/app/oracle/oradata/grs/undotbs01.dbf'

SQL> select * from v$datafile;--能看见删除的undo dbf

create pfile='/u01/app/oracle/pfile1' from spfile;

[oracle@localhost grs]$ vi /u01/app/oracle/pfile1 

grs.__db_cache_size=209715200

grs.__java_pool_size=4194304

grs.__large_pool_size=4194304

grs.__shared_pool_size=58720256

grs.__streams_pool_size=4194304

*.audit_file_dest='/u01/app/oracle/admin/grs/adump'

*.background_dump_dest='/u01/app/oracle/admin/grs/bdump'

*.compatible='10.2.0.1.0'

*.control_files='/u01/app/oracle/oradata/grs/control01.ctl','/u01/app/oracle/oradata/grs/control02.ctl','/u01/app/oracle/oradata/grs/control03.ctl'#Restore Controlfile

*.core_dump_dest='/u01/app/oracle/admin/grs/cdump'

*.db_block_size=8192

*.db_domain=''

*.db_file_multiblock_read_count=16

*.db_name='grs'

*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'

*.db_recovery_file_dest_size=2147483648

*.dispatchers='(PROTOCOL=TCP) (SERVICE=grsXDB)'

*.job_queue_processes=10

*.log_archive_dest_1='location=/u01/app/oracle/archivelog/archivelog/'

*.open_cursors=300

*.pga_aggregate_target=94371840

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.sga_target=285212672

*.undo_management='MANUAL'-----改为manual

*.undo_tablespace='UNDOTBS1'

*._corrupted_rollback_segments=(_SYSSMU1$,_SYSSMU2$,_SYSSMU3$,_SYSSMU4$,_SYSSMU5$,_SYSSMU6$,_SYSSMU7$,_SYSSMU8$,_SYSSMU9$,_SYSSMU10$,_SYSSMU11$)----添加

*._allow_resetlogs_corruption=true---隐藏参数

*.user_dump_dest='/u01/app/oracle/admin/grs/udump'

~

 

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL>  startup pfile='/u01/app/oracle/pfile1' mount;

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              71304784 bytes

Database Buffers          209715200 bytes

Redo Buffers                2973696 bytes

Database mounted.

SQL> recover database until cancel;

Media recovery complete.

SQL> ALTER DATABASE DATAFILE  '/u01/app/oracle/oradata/grs/undotbs01.dbf' OFFLINE DROP;

 

Database altered.

 

SQL>  alter database open resetlogs;

 

Database altered.

 

SQL> SELECT SEGMENT_NAME, OWNER, TABLESPACE_NAME, STATUS  FROM DBA_ROLLBACK_SEGS;

 

SEGMENT_NAME                   OWNER  TABLESPACE_NAME                STATUS

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

SYSTEM                         SYS    SYSTEM                         ONLINE

_SYSSMU11$                     PUBLIC UNDOTBS1                       NEEDS RECOVERY

SQL> DROP ROLLBACK SEGMENT "_SYSSMU11$";---出现次错误,检查写法是否正确,关闭db,在pfile中的参数*._corrupted_rollback_segments中增加"_SYSSMU11$"

DROP ROLLBACK SEGMENT "_SYSSMU11$"

*

ERROR at line 1:

ORA-30025: DROP segment '_SYSSMU11$' (in undo tablespace) not allowed

SQL> DROP ROLLBACK SEGMENT "_SYSSMU11$";

 

Rollback segment dropped.

 

SQL>  DROP TABLESPACE UNDOTBS1 INCLUDING CONTENTS AND DATAFILES;

 

Tablespace dropped.

 

SQL>    create undo tablespace UNDOTBS1 datafile '/u01/app/oracle/oradata/grs/undotbs01.dbf'  size 100m;

 

Tablespace created.

 

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

[oracle@localhost grs]$ vi /u01/app/oracle/pfile1----修改的另外一个pfile的副本

---去掉隐藏参数,

*.remote_login_passwordfile='EXCLUSIVE'

*.sga_target=285212672

*.undo_management='AUTO'

*.undo_tablespace='UNDOTBS1'

*.user_dump_dest='/u01/app/oracle/admin/grs/udump'

SQL> startup;-----这里默认启用spfile,                                         

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              71304784 bytes

Database Buffers          209715200 bytes

Redo Buffers                2973696 bytes

Database mounted.

Database opened.

 

5 归档,rman全备份,控制文件全部丢失

 

update xx set ename='20134978'

 

select * from xx

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

[oracle@localhost grs]$ mv control01.ctl control02.ctl control03.ctl ./control_backup/

---移除控制文件

[oracle@localhost grs]$ ll

SQL> startup

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size      1218992 bytes

Variable Size      75499088 bytes

Database Buffers      205520896 bytes

Redo Buffers        2973696 bytes

ORA-00205: error in identifying control file, check alert log for more info

--启动报错

查看alert 日志

[oracle@localhost grs]$ tail -f -n 20  /u01/app/oracle/admin/grs/bdump/alert_grs.log

LGWR started with pid=6, OS id=28040

CKPT started with pid=7, OS id=28042

SMON started with pid=8, OS id=28044

RECO started with pid=9, OS id=28046

CJQ0 started with pid=10, OS id=28048

MMON started with pid=11, OS id=28050

Thu Mar 20 16:25:14 2014

starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...

MMNL started with pid=12, OS id=28052

Thu Mar 20 16:25:14 2014

starting up 1 shared server(s) ...

Thu Mar 20 16:25:15 2014

ALTER DATABASE   MOUNT

Thu Mar 20 16:25:15 2014

ORA-00202: control file: '/u01/app/oracle/oradata/grs/control01.ctl'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

Thu Mar 20 16:25:18 2014

ORA-205 signalled during: ALTER DATABASE   MOUNT...

[oracle@localhost grs]$ rman target/

 

Recovery Manager: Release 10.2.0.1.0 - Production on Thu Mar 20 16:26:40 2014

 

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

connected to target database: grs (not mounted)

 

RMAN> set DBID=325518186

 

executing command: SET DBID

 

RMAN> show all;

 

using target database control file instead of recovery catalog

RMAN configuration parameters 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 ARCHIVELOG DELETION POLICY TO NONE; # default

RMAN> restore controlfile from '/u01/oracle/backup/rman_backup_c-325518186-20140320-01';

 

Starting restore at 20-MAR-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=155 devtype=DISK

 

channel ORA_DISK_1: restoring control file

channel ORA_DISK_1: restore complete, elapsed time: 00:00:05

output filename=/u01/app/oracle/oradata/grs/control01.ctl

output filename=/u01/app/oracle/oradata/grs/control02.ctl

output filename=/u01/app/oracle/oradata/grs/control03.ctl

Finished restore at 20-MAR-14

 

RMAN> alter database mount;

 

database mounted

released channel: ORA_DISK_1

 

RMAN> recover database;

 

Starting recover at 20-MAR-14

Starting implicit crosscheck backup at 20-MAR-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=155 devtype=DISK

Crosschecked 4 objects

Finished implicit crosscheck backup at 20-MAR-14

 

Starting implicit crosscheck copy at 20-MAR-14

using channel ORA_DISK_1

Finished implicit crosscheck copy at 20-MAR-14

 

searching for all files in the recovery area

cataloging files...

no files cataloged

 

using channel ORA_DISK_1

 

starting media recovery

 

archive log thread 1 sequence 7 is already on disk as file /u01/app/oracle/oradata/grs/redo02.log

archive log filename=/u01/app/oracle/oradata/grs/redo02.log thread=1 sequence=7

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

Finished recover at 20-MAR-14

RMAN> alter database open resetlogs;

以控制文件恢复,需要resetlogs方式打开db

database opened

 

RMAN>

 

select * from xx

查看数据正常

6 归档,无备份,控制文件全部丢失

--从新创建控制文件

在internal或sys 下运行如下创建控制文件的脚本,注意完整列出联机日志或数据文件的路径,或修改由 alter database backup control file to trace 备份控制文件时产生的脚本,去掉多余的注释即可。

SQL> alter database backup controlfile to trace as'/u01/oracle/backup/control_trace.sql';

 

Database altered.

user_dump_dest

alter database backup controlfile to trace as'/u01/oracle/backup/control_trace.sql';

idle> recover database using backup controlfile until cancel;

CREATE CONTROLFILE REUSE DATABASE grs2 NORESETLOGS ARCHIVELOG

    MAXLOGFILES 16

    MAXLOGMEMBERS 3

    MAXDATAFILES 100

    MAXINSTANCES 8

    MAXLOGHISTORY 292

LOGFILE

  GROUP 1 '/u02/app/oracle/oradata/grs2/redo01.log'  SIZE 50M,

  GROUP 2 '/u02/app/oracle/oradata/grs2/redo02.log'  SIZE 50M,

  GROUP 3 '/u02/app/oracle/oradata/grs2/redo03.log'  SIZE 50M

DATAFILE

  '/u02/app/oracle/oradata/grs2/system01.dbf',

  '/u02/app/oracle/oradata/grs2/undotbs01.dbf',

  '/u02/app/oracle/oradata/grs2/sysaux01.dbf',

  '/u02/app/oracle/oradata/grs2/users01.dbf',

  '/u02/app/oracle/oradata/grs2/example01.dbf',

  '/u02/app/oracle/oradata/grs2/yyhhqq.dbf',

  '/u02/app/oracle/oradata/grs2/cmask01.dbf',

  '/u02/app/oracle/oradata/grs2/rman_catalog.dbf',

  '/u02/app/oracle/oradata/grs2/rman_test.dbf',

  '/u02/app/oracle/oradata/grs2/data_test.dbf'

CHARACTER SET AL32UTF8

;

7 归档,有备份,非当前redo丢失

update xx set ename='erererl' commit

[oracle@localhost grs]$ rm redo03.log

SQL> startup;

ORACLE instance started.

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              75499088 bytes

Database Buffers          205520896 bytes

Redo Buffers                2973696 bytes

Database mounted.

ORA-00313: open failed for members of log group 3 of thread 1

ORA-00312: online log 3 thread 1: '/u01/app/oracle/oradata/grs/redo03.log'

SQL> set linesize 1000

SQL> set pagesize 1000

SQL> select * from v$log;----日志3是未使用状态

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME

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

         1          1          2   52428800          1 NO  CURRENT                3252428 21-MAR-14

         3          1          0   52428800          1 YES UNUSED                       0

         2          1          1   52428800          1 YES INACTIVE               3219698 20-MAR-14

SQL> alter database clear logfile group 3;---重建该组重做日志组

如果是该日志组还没有归档,则需要用 

> alter database clear unarchived logfile group 3;

Database altered.

SQL> alter database open;

 

Database altered.

select * from xx;---未提交的,回滚

说明: 

1、如果损坏的是非当前的联机日志文件,一般只需要 clear 就可以重建该日志文件,但是如果该数据库处于归档状态但该日志还没有归档,就需要强行 clear

2、建议clear,特别是强行 clear后作一次数据库的全备份。

3、此方法适用于归档与非归档数据库。

http://www.itpub.net/thread-1824825-1-1.html

总结,对于不是当前使用的归档日志损坏,归档模式需要使用alter database clear unarchived 命令清空日志 组即可。对于非归档模式需要使用alter system clear 日志文件组即可。

 

8 丢失当前redo,归档,有备份

归档模式下当前日志的损坏有两种情况: 

一、是数据库是正常关闭,日志文件中没有未解决的事务需要实例恢复,当前日志组的损坏就可以直接用alter database clear unarchived logfile group n 来重建。

二、是日志组中有活动的事务,数据库需要媒体恢复,日志组需要用来同步,有两种补救办

法: 

A.最好的办法就是通过不完全恢复,可以保证数据库的一致性,但是这种办法要求在归档方式下,并且有可用的备份。 

B.通过强制性恢复,但是可能导致数据库不一致。

下面分别用来说明这两种恢复方法

1 归档有备份,采用不完全恢复

select * from v$log;

1 1 2 52428800 1 YES INACTIVE 3252428 2014-3-21 5:31:00

2 1 1 52428800 1 YES INACTIVE 3219698 2014-3-20 16:29:31

3 1 3 52428800 1 NO CURRENT 3271167 2014-3-21 14:36:45

--删除文件3

[oracle@localhost grs]$ rm redo03.log

SQL> startup;

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              75499088 bytes

Database Buffers          205520896 bytes

Redo Buffers                2973696 bytes

Database mounted.

ORA-00313: open failed for members of log group 3 of thread 1

ORA-00312: online log 3 thread 1: '/u01/app/oracle/oradata/grs/redo03.log'

SQL> alter database clear unarchived logfile group 3;

alter database clear unarchived logfile group 3

*

ERROR at line 1:

ORA-00313: open failed for members of log group 3 of thread 1

ORA-00312: online log 3 thread 1: '/u01/app/oracle/oradata/grs/redo03.log'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

SQL> select group#,sequence#,archived,status from v$log; 

 

    GROUP#  SEQUENCE# ARC STATUS

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

         1          2 YES INACTIVE

         3          0 NO  CLEARING_CURRENT

         2          0 YES UNUSED

 

RMAN> restore database;

 

Starting restore at 21-MAR-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=151 devtype=DISK

 

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to /u01/app/oracle/oradata/grs/system01.dbf

restoring datafile 00002 to /u01/app/oracle/oradata/grs/undotbs01.dbf

restoring datafile 00003 to /u01/app/oracle/oradata/grs/sysaux01.dbf

restoring datafile 00004 to /u01/app/oracle/oradata/grs/users01.dbf

restoring datafile 00005 to /u01/app/oracle/oradata/grs/example01.dbf

restoring datafile 00006 to /u01/app/oracle/oradata/grs/yyhhqq.dbf

restoring datafile 00007 to /u01/app/oracle/oradata/grs/cmask01.dbf

restoring datafile 00008 to /u01/app/oracle/oradata/grs/rman_catalog.dbf

restoring datafile 00009 to /u01/app/oracle/oradata/grs/rman_test.dbf

channel ORA_DISK_1: reading from backup piece /u01/oracle/backup/rman_backup_2gp3lmi7

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/oracle/backup/rman_backup_2gp3lmi7 tag=TAG20140320T161606

channel ORA_DISK_1: restore complete, elapsed time: 00:04:28

Finished restore at 21-MAR-14

 

RMAN> run{

2> sql'alter session set nls_date_format="YYYY-MM-DD HH24:MI:SS"';

3> set until time '2014-03-21 15:45:04';

4> recover database;

5> };

 

sql statement: alter session set nls_date_format="YYYY-MM-DD HH24:MI:SS"

 

executing command: SET until clause

 

Starting recover at 21-MAR-14

using channel ORA_DISK_1

 

starting media recovery

 

archive log thread 1 sequence 6 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_6_842630868.dbf

archive log thread 1 sequence 7 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_7_842630868.dbf

archive log thread 1 sequence 1 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_1_842718571.dbf

archive log thread 1 sequence 2 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_2_842718571.dbf

archive log filename=/u01/app/oracle/archivelog/archivelog/1_6_842630868.dbf thread=1 sequence=6

archive log filename=/u01/app/oracle/archivelog/archivelog/1_7_842630868.dbf thread=1 sequence=7

archive log filename=/u01/app/oracle/archivelog/archivelog/1_1_842718571.dbf thread=1 sequence=1

unable to find archive log

archive log thread=1 sequence=3

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

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

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

RMAN-03002: failure of recover command at 03/21/2014 16:06:52

RMAN-06054: media recovery requesting unknown log: thread 1 seq 3 lowscn 3271167

 

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

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

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

RMAN-00558: error encountered while parsing input commands

RMAN-01009: syntax error: found ";": expecting one of: "allocate, alter, backup, beginline, blockrecover, catalog, change, connect, copy, convert, create, crosscheck, configure, duplicate, debug, delete, drop, exit, endinline, flashback, host, {, library, list, mount, open, print, quit, recover, register, release, replace, report, renormalize, reset, restore, resync, rman, run, rpctest, set, setlimit, sql, switch, spool, startup, shutdown, send, show, test, transport, upgrade, unregister, validate"

RMAN-01007: at line 0 column 2 file: standard input

 

RMAN>

SQL> alter database open resetlogs;

 

Database altered.

 

2 采用隐藏的初始化参数来恢复

SQL> shutdown abort;

ORACLE instance shut down.

SQL> startup;

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              75499088 bytes

Database Buffers          205520896 bytes

Redo Buffers                2973696 bytes

Database mounted.

ORA-00313: open failed for members of log group 1 of thread 1

ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/grs/redo01.log'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

SQL> select group#,sequence#,archived,status from v$log;

 

    GROUP#  SEQUENCE# ARC STATUS

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

         1          2 NO  CURRENT

         3          1 YES INACTIVE

         2          0 YES UNUSED

 

SQL> alter database clear unarchived logfile group 1;

alter database clear unarchived logfile group 1

*

ERROR at line 1:

ORA-01624: log 1 needed for crash recovery of instance grs (thread 1)

ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/grs/redo01.log'

SQL> alter system set "_allow_resetlogs_corruption"=TRUE  scope=spfile;

System altered.

SQL> shutdown immediate;

ORA-01109: database not open

Database dismounted.

ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              75499088 bytes

Database Buffers          205520896 bytes

Redo Buffers                2973696 bytes

Database mounted.

SQL> recover database until cancel;

ORA-00279: change 3273739 generated at 03/21/2014 16:07:22 needed for thread 1

ORA-00289: suggestion : /u01/app/oracle/archivelog/archivelog/1_2_842803635.dbf

ORA-00280: change 3273739 for thread 1 is in sequence #2

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

cancel

ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below

ORA-01194: file 1 needs more recovery to be consistent

ORA-01110: data file 1: '/u01/app/oracle/oradata/grs/system01.dbf'

ORA-01112: media recovery not started

SQL> alter database open resetlogs;

Database altered.

SQL> select * from v$log;

 

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME

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

         1          1          1   52428800          1 NO  CURRENT                3273740 21-MAR-14

         2          1          0   52428800          1 YES UNUSED                       0

         3          1          0   52428800          1 YES UNUSED                       0

[oracle@localhost grs]$ tail -f -n 20  /u01/app/oracle/admin/grs/bdump/alert_grs.log

select * from xx;----更新的丢失了

 

System parameters with non-default values:

  processes                = 150

  __shared_pool_size       = 62914560

  __large_pool_size        = 4194304

  __java_pool_size         = 4194304

  __streams_pool_size      = 4194304

  sga_target               = 285212672

  control_files            = /u01/app/oracle/oradata/grs/control01.ctl, /u01/app/oracle/oradata/grs/control02.ctl, /u01/app/oracle/oradata/grs/control03.ctl

  db_block_size            = 8192

  __db_cache_size          = 205520896

  compatible               = 10.2.0.1.0

  log_archive_dest_1       = location=/u01/app/oracle/archivelog/archivelog/

  db_file_multiblock_read_count= 16

  db_recovery_file_dest    = /u01/app/oracle/flash_recovery_area

  db_recovery_file_dest_size= 2147483648

  _allow_resetlogs_corruption= TRUE

  undo_management          = AUTO

  undo_tablespace          = UNDOTBS1

  remote_login_passwordfile= EXCLUSIVE

  db_domain                =

  dispatchers              = (PROTOCOL=TCP) (SERVICE=grsXDB)

  job_queue_processes      = 10

  background_dump_dest     = /u01/app/oracle/admin/grs/bdump

  user_dump_dest           = /u01/app/oracle/admin/grs/udump

  core_dump_dest           = /u01/app/oracle/admin/grs/cdump

  audit_file_dest          = /u01/app/oracle/admin/grs/adump

  db_name                  = grs

  open_cursors             = 300

  pga_aggregate_target     = 94371840

进行full expdp,然后重新创建db,在impdp(一些配置需要修改,比如归档,rman等)

SQL> alter database archivelog;

 

Database altered.

SQL> alter system set  log_archive_dest_1='location=/u01/app/oracle/archivelog/archivelog/';

SQL> alter database open;

System altered.

 

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            /u01/app/oracle/archivelog/archivelog/

Oldest online log sequence     4

Next log sequence to archive   6

Current log sequence           6

SQL> show parameter user_dump_dest;

 

NAME                                 TYPE        VALUE

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

user_dump_dest                       string      /u01/app/oracle/admin/grs/udum

                                                 p

SQL>

[oracle@localhost ~]$ export LC_ALL=en_US

[oracle@localhost ~]$ dbca

[oracle@localhost ~]$ netca

Oracle Net Services Configuration:

Oracle Net Services configuration terminated by user.  The exit code is -1

 

[oracle@localhost ~]$ sqlplus  /nolog

 

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Mar 24 15:46:01 2014

 

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

SQL> conn /as sysdba

Connected.

SQL>  create directory expdp_file_dir as '/u02/oracleexp';

 

Directory created.

 

SQL> alter user scott account unlock;

 

User altered.

 

SQL>  alter user scott identified by "987064";

 

User altered.

SQL> grant dba to scott;

Grant succeeded.

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> exit

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

[oracle@localhost ~]$  impdp scott/987064 directory=expdp_file_dir dumpfile=all_expdp_20140324.DMP nologfile=Y full=y parallel=4;

Import: Release 10.2.0.1.0 - Production on Monday, 24 March, 2014 15:57:38

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

UDI-00008: operation generated ORACLE error 1034

ORA-01034: ORACLE not available

ORA-27101: shared memory realm does not exist

Linux Error: 2: No such file or directory

UDI-00003: all allowable logon attempts failed

 

[oracle@localhost ~]$ sqlplus /nolog

 

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Mar 24 15:58:05 2014

 

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

SQL> conn /as sysdba

Connected to an idle instance.

SQL> startup;

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              92276304 bytes

Database Buffers          188743680 bytes

Redo Buffers                2973696 bytes

Database mounted.

Database opened.

 

  http://192.168.2.185:1158/em/console/

  </collection>[oracle@localhost test_xml]$ emctl status dbconsole

TZ set to PRC

Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0  

Copyright (c) 1996, 2005 Oracle Corporation.  All rights reserved.

http://localhost.localdomain:1158/em/console/aboutApplication

Oracle Enterprise Manager 10g is running. 

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

Logs are generated in directory /u01/app/oracle/product/10.2.0/db_1/localhost.localdomain_grs/sysman/log

 

9 归档模式,无备份,丢失一个数据文件

1 系统恢复

[oracle@localhost ~]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 25 10:58:18 2014

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL> conn /as sysdba

Connected to an idle instance.

SQL> startup;

ORACLE instance started.

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size             113247824 bytes

Database Buffers          167772160 bytes

Redo Buffers                2973696 bytes

Database mounted.

Database opened.

SQL> CREATE TABLESPACE data_test DATAFILE

'/u01/app/oracle/oradata/grs/data_test.dbf'SIZE 10M AUTOEXTEND ON NEXT 10M MAXSIZE 20M  2  ;

 

Tablespace created.

SQL> create table data_test(a number) TABLESPACE data_test;

Table created.

SQL> insert into data_test

  2  select rownum from dual connect by rownum<=10;

10 rows created.

SQL> select * from data_test;

         A

----------

         1

         2

         3

         4

         5

         6

         7

         8

         9

        10

10 rows selected.

SQL> commit;

Commit complete.

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> !rm '/u01/app/oracle/oradata/grs/data_test.dbf';

[oracle@localhost grs]$ rm data_test.dbf----二者一样

SQL> startup;

ORACLE instance started.

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size             104859216 bytes

Database Buffers          176160768 bytes

Redo Buffers                2973696 bytes

Database mounted.

ORA-01157: cannot identify/lock data file 10 - see DBWR trace file

ORA-01110: data file 10: '/u01/app/oracle/oradata/grs/data_test.dbf'

SQL> alter database create datafile '/u01/app/oracle/oradata/grs/data_test.dbf'as  '/u01/app/oracle/oradata/grs/data_test.dbf';

-----------重建该文件,

Database altered.

SQL> recover datafile 10;---该数据文件从创建起的所有的redo文件还在,就可以修复

Media recovery complete.

SQL> alter database open;

Database altered.

SQL> select * from data_test;

 

         A

----------

         1

         2

         3

         4

         5

         6

         7

         8

         9

        10

 

10 rows selected.

2 利用rman来恢复

  重复上述步骤到start

SQL> startup;

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size             113247824 bytes

Database Buffers          167772160 bytes

Redo Buffers                2973696 bytes

Database mounted.

ORA-01157: cannot identify/lock data file 10 - see DBWR trace file

ORA-01110: data file 10: '/u01/app/oracle/oradata/grs/data_test.dbf'

[oracle@localhost grs]$ rman target/

 

Recovery Manager: Release 10.2.0.1.0 - Production on Tue Mar 25 15:22:36 2014

 

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

connected to target database: GRS (DBID=341090406, not open)

 

RMAN> restore datafile 10;

Starting restore at 25-MAR-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=155 devtype=DISK

creating datafile fno=10 name=/u01/app/oracle/oradata/grs/data_test.dbf

restore not done; all files readonly, offline, or already restored

Finished restore at 25-MAR-14

RMAN> recover datafile 10;

Starting recover at 25-MAR-14

using channel ORA_DISK_1

starting media recovery

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

Finished recover at 25-MAR-14

RMAN> alter database open;   

database opened

RMAN> sql'select * from data_test';

sql statement: select * from data_test

也可以是,恢复表空间

run{

allocate channel c1 type disk;

restore tablespace users;

recover tablespace users;

sql 'alter database datafile 6 online';

release channel c1;

}

在丢失多个数据文件时:

当启动检查数据文件丢失报错时可以查看该视图看需要恢复的数据文件有哪些

select * from v$recover_file;   

FILE# ONLINE  ONLINE_ ERROR                CHANGE# TIME

10 归档模式,有备份,丢失一个数据文件

 

RMAN> backup tablespace data_test format '/u01/oracle/backup/rman_back20140325_%U';

Starting backup at 25-MAR-14

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00010 name=/u01/app/oracle/oradata/grs/data_test.dbf

channel ORA_DISK_1: starting piece 1 at 25-MAR-14

channel ORA_DISK_1: finished piece 1 at 25-MAR-14

piece handle=/u01/oracle/backup/rman_back20140325_06p42qal_1_1 tag=TAG20140325T154005 comment=NONE

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

Finished backup at 25-MAR-14

Starting Control File and SPFILE Autobackup at 25-MAR-14

piece handle=/u01/oracle/backup/rman_backup_c-341090406-20140325-01 comment=NONE

Finished Control File and SPFILE Autobackup at 25-MAR-14

RMAN> exit;

Recovery Manager complete.

[oracle@localhost grs]$ rm data_test.dbf

SQL> insert into data_test

  2  select rownum from dual connect by rownum<=10;

10 rows created.

SQL> select * from data_test;

         A

----------

         1

         2

         3

         4

         5

         6

         7

         8

         9

        10

         1

 

         A

----------

         2

         3

         4

         5

         6

         7

         8

         9

        10

 

20 rows selected.

SQL> shutdown immediate;

ORA-01097: cannot shutdown while in a transaction - commit or rollback first

SQL> commit;

Commit complete.

SQL> shutdown immediate;

SQL> startup;

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size             117442128 bytes

Database Buffers          163577856 bytes

Redo Buffers                2973696 bytes

Database mounted.

ORA-01157: cannot identify/lock data file 10 - see DBWR trace file

ORA-01110: data file 10: '/u01/app/oracle/oradata/grs/data_test.dbf'

SQL> set linesize 1000

SQL> set pagesize 1000

SQL> select * from v$recover_file;

 

     FILE# ONLINE ONLINE_ ERROR                                                                CHANGE# TIME

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

        10 ONLINE ONLINE  FILE NOT FOUND                                                             0

------可以先open数据库在offline,恢复-----减少停机时间

------可以执行rman进行恢复

SQL> alter database datafile 10 offline drop;

Database altered.

SQL> alter database open;

Database altered.

RMAN> restore datafile 10;

Starting restore at 25-MAR-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=137 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00010 to /u01/app/oracle/oradata/grs/data_test.dbf

channel ORA_DISK_1: reading from backup piece /u01/oracle/backup/rman_back20140325_06p42qal_1_1

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/oracle/backup/rman_back20140325_06p42qal_1_1 tag=TAG20140325T154005

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

Finished restore at 25-MAR-14

RMAN> recover datafile 10;

Starting recover at 25-MAR-14

using channel ORA_DISK_1

starting media recovery

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

Finished recover at 25-MAR-14

RMAN> sql'alter database datafile 10 online';

sql statement: alter database datafile 10 online

SQL> select * from data_test;

         A

----------

         1

         2

         3

         4

         5

         6

         7

         8

         9

        10

         1

         2

         3

         4

         5

         6

         7

         8

         9

        10

 

20 rows selected.

 

 

11 基于时间的不完全恢复

OS 热备份下的基于时间的恢复

不完全恢复可以分为基于时间的恢复,基于改变的恢复与基于撤消的恢复,这里已基于时间

的恢复为例子来说明不完全恢复过程。 

基于时间的恢复可以不完全恢复到现在时间之前的某一个时间,对于某些误操作,如删除了

一个数据表,可以在备用恢复环境上恢复到表的删除时间之前,然后把该表导出到正式环境,避

免一个人为的错误。

SQL> create table test(a int);

Table created.

SQL>  insert into test values(1);   

1 row created.

SQL> commit;

Commit complete.

进行全备份

SQL> insert into data_test

  2  select rownum from dual connect by rownum<=5;

5 rows created.

SQL> alter system switch logfile;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

 

TO_CHAR(SYSDATE,'YY

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

2014-03-25 16:11:47

SQL> drop table data_test;

 

Table dropped.

RMAN> shutdown immediate;

 

database closed

database dismounted

Oracle instance shut down

 

RMAN> startup mount;

 

connected to target database (not started)

Oracle instance started

database mounted

 

Total System Global Area     285212672 bytes

 

Fixed Size                     1218992 bytes

Variable Size                121636432 bytes

Database Buffers             159383552 bytes

Redo Buffers                   2973696 bytes

RMAN> restore database;

 

Starting restore at 25-MAR-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=157 devtype=DISK

 

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to /u01/app/oracle/oradata/grs/system01.dbf

restoring datafile 00002 to /u01/app/oracle/oradata/grs/undotbs01.dbf

restoring datafile 00003 to /u01/app/oracle/oradata/grs/sysaux01.dbf

restoring datafile 00004 to /u01/app/oracle/oradata/grs/users01.dbf

restoring datafile 00005 to /u01/app/oracle/oradata/grs/example01.dbf

restoring datafile 00006 to /u01/app/oracle/oradata/grs/yyhhqq.dbf

restoring datafile 00007 to /u01/app/oracle/oradata/grs/cmask01.dbf

restoring datafile 00008 to /u01/app/oracle/oradata/grs/rman_catalog.dbf

restoring datafile 00009 to /u01/app/oracle/oradata/grs/rman_test.dbf

channel ORA_DISK_1: reading from backup piece /u01/oracle/backup/rman_backup_02p40cjv

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/oracle/backup/rman_backup_02p40cjv tag=TAG20140324T173351

channel ORA_DISK_1: restore complete, elapsed time: 00:02:06

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00010 to /u01/app/oracle/oradata/grs/data_test.dbf

channel ORA_DISK_1: reading from backup piece /u01/oracle/backup/rman_back20140325_06p42qal_1_1

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/oracle/backup/rman_back20140325_06p42qal_1_1 tag=TAG20140325T154005

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

Finished restore at 25-MAR-14

RMAN> run{

2> sql 'alter session set nls_date_format= "YYYY-MM-DD HH24:MI:SS"';

3> set until time '2014-03-25 16:11:47';

4> recover database;

5> };

 

sql statement: alter session set nls_date_format= "YYYY-MM-DD HH24:MI:SS"

 

executing command: SET until clause

 

Starting recover at 25-MAR-14

using channel ORA_DISK_1

 

starting media recovery

 

archive log thread 1 sequence 8 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_8_843061290.dbf

archive log thread 1 sequence 9 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_9_843061290.dbf

archive log thread 1 sequence 10 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_10_843061290.dbf

archive log thread 1 sequence 11 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_11_843061290.dbf

channel ORA_DISK_1: starting archive log restore to default destination

channel ORA_DISK_1: restoring archive log

archive log thread=1 sequence=7

channel ORA_DISK_1: reading from backup piece /u01/oracle/backup/rman_backup_03p40cph

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/oracle/backup/rman_backup_03p40cph tag=TAG20140324T173648

channel ORA_DISK_1: restore complete, elapsed time: 00:00:02

archive log filename=/u01/app/oracle/archivelog/archivelog/1_7_843061290.dbf thread=1 sequence=7

archive log filename=/u01/app/oracle/archivelog/archivelog/1_8_843061290.dbf thread=1 sequence=8

archive log filename=/u01/app/oracle/archivelog/archivelog/1_9_843061290.dbf thread=1 sequence=9

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

Finished recover at 25-MAR-14

 

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

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

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

RMAN-00558: error encountered while parsing input commands

RMAN-01009: syntax error: found ";": expecting one of: "allocate, alter, backup, beginline, blockrecover, catalog, change, connect, copy, convert, create, crosscheck, configure, duplicate, debug, delete, drop, exit, endinline, flashback, host, {, library, list, mount, open, print, quit, recover, register, release, replace, report, renormalize, reset, restore, resync, rman, run, rpctest, set, setlimit, sql, switch, spool, startup, shutdown, send, show, test, transport, upgrade, unregister, validate"

RMAN-01007: at line 0 column 2 file: standard input

 

RMAN> alter database open resetlogs;

 

database opened

SQL> conn /as sysdba

Connected.

SQL> select * from data_test;

 

         A

----------

         1

         2

         3

         4

         5

         6

         7

         8

         9

        10

         1

 

         A

----------

         2

         3

         4

         5

         6

         7

         8

         9

        10

 

20 rows selected.

 

12 基于改变的恢复 rman有备份

SQL> insert into t 

  2  values ('1',20140419);

 

1 row created.

 

SQL> commit;

 

Commit complete.

 

SQL> select * from t;

 

PROD       CHANNEL

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

у搧1      1,2,3

у搧2      1,2

у搧3      2,4

1          20140419

SQL> alter system switch logfile;

 

System altered.

SQL> select dbms_flashback.get_system_change_number from dual; 

 

GET_SYSTEM_CHANGE_NUMBER

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

                 4203003

 

SQL> drop table t;

 

Table dropped.

恢复到SCN 4203003,先关闭数据库,然后启动到 mount 下

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size              96470608 bytes

Database Buffers          184549376 bytes

Redo Buffers                2973696 bytes

Database mounted.

 

[oracle@localhost ~]$ rman target/

 

Recovery Manager: Release 10.2.0.1.0 - Production on Wed Apr 9 16:50:24 2014

 

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

connected to target database: GRS (DBID=341090406, not open)

 

RMAN> run{

2> allocate channel c1 type disk;   

3> restore database;   

recover database until scn 4203003;

sql 'ALTER DATABASE OPEN RESETLOGS';

4> 5> 6> release channel c1;

7> };

 

SQL> conn

Enter user-name: scott

Enter password:

Connected.

SQL> select * from t;

 

PROD       CHANNEL

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

у搧1      1,2,3

у搧2      1,2

у搧3      2,4

1          20140419

1RMAN 也可以实现不完全恢复,方法比 OS 备份恢复的方法更简单可靠

2RMAN 可以基于时间,基于改变与基于日志序列的不完全恢复,基于日志序列的恢

复可以指定恢复到哪个日志序列,如 

run {    

allocate channel ch1 type disk;    

allocate channel ch2 type 'sbt_tape';   

set until logseq 1234 thread 1;   

restore controlfile to '$ORACLE_HOME/dbs/cf1.f'     

replicate controlfile from '$ORACLE_HOME/dbs/cf1.f';   

alter database mount;    

restore database;    

recover database;    

sql "ALTER DATABASE OPEN RESETLOGS";

}

3与所有的不完全恢复一样,必须在 mount下,restore所有备份数据文件,需要

resetlogs。

4、基于改变的恢复比基于时间的恢复更可靠,但是可能也更复杂,需要知道需要恢复

到哪一个改变号(SCN),在正常生产中,获取SCN的办法其实也有很多,如查询数据库字典

表(V$archived_log or v$log_history),或分析归档与联机日志(logmnr)等

posted @ 2018-11-07 14:18  春困秋乏夏打盹  阅读(1485)  评论(0编辑  收藏  举报