当前位置:Gxlcms > 数据库问题 > oracle数据库热备中的备份和恢复及例子

oracle数据库热备中的备份和恢复及例子

时间:2021-07-01 10:21:17 帮助过:18人阅读


/u01/flash_recovery_area/PROD/archivelog/2017_11_13/o1_mf_1_2_f0lo0fom_.arc

因为今天13号所以选这两条日志,也可以多切换几次日志多生成几个日志条目

接下来进行时间的挖掘(基于时间点来恢复)

mkdir -p /home/oracle/logmnr

show parameter utl_file_dir

alter system set utl_file_dir=‘/home/oracle/logmnr‘ scope=spfile;

startup force;

show parameter utl_file_dir;

alter database add supplemental log data;

execute dbms_logmnr_d.build(‘dict.ora‘,‘/home/oracle/logmnr‘,dbms_logmnr_d.store_in_flat_file); 

execute dbms_logmnr.add_logfile(logfilename=>‘/u01/flash_recovery_area/PROD/archivelog/2017_11_13/o1_mf_1_1_f0lkgyt6_.arc‘,options=>dbms_logmnr.new);

execute dbms_logmnr.add_logfile(logfilename=>‘/u01/flash_recovery_area/PROD/archivelog/2017_11_13/o1_mf_1_2_f0lo0fom_.arc‘,options=>dbms_logmnr.addfile);

execute dbms_logmnr.start_logmnr(dictfilename=>‘/home/oracle/logmnr/dict.ora‘,options=>dbms_logmnr.ddl_dict_tracking);

select username,scn,to_char(timestamp,‘yyyy-mm-dd hh24:mi:ss‘) time,sql_redo from v$logmnr_contents WHERE lower(sql_redo) like ‘drop table%‘;
execute dbms_logmnr.end_logmnr;

USERNAME SCN TIME
------------------------------ ---------- -------------------
SQL_REDO
------------------------------------------------------------
UNKNOWN 954522 2017-11-13 16:03:53
drop table emp1 purge;

(记录此时间2017-11-13 16:03:53)

shutdown abort;

时间挖掘完成。

cd /home/oradata/prod

rm *.dbf

cp /home/oracle/hot_backup/*.dbf ./

startup;

recover database until time ‘2017-11-13 16:03:53‘;auto

alter database open resetlogs;

验证查看

select * from emp1;

成功找回此表,同样可以通过scn号寻找恢复,但是不能用闪回表因为我是purge彻底删除,只能不完全恢复。

2.模拟user01.dbf 介质损坏

rm -rf /u01/oradata/prod/users01.dbf

例如shutdown immediate

SYS@prod>shutdown immediate
ORA-01116: 打开数据库文件 4 时出错
ORA-01110: 数据文件 4: ‘/u01/oradata/prod/users01.dbf‘
ORA-27041: 无法打开文件

解决:

alter system flush buffer_cache;

alter tablespace users offline immediate;

cp /home/oracle/hot_backup/users01.dbf /u01/oradata/prod/

recover tablespace users;auto

alter tablespace users online;

3.模拟undotbs1 介质损坏(恢复的方法多种我只演示根据文件号恢复)

select name  from v$datafile;

rm -rf /u01/oradata/prod/undotbs01.dbf

shutdown abort

解决:

SYS@prod>select FILE#,ERROR from v$recover_file;

FILE# ERROR
---------- -----------------------------------------------------------------
1 UNKNOWN ERROR
2 UNKNOWN ERROR
3 FILE NOT FOUND

SYS@prod>select FILE#,NAME from v$datafile;

FILE#                                     NAME

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

1                                         /u01/oradata/prod/system01.dbf

2                                         /u01/oradata/prod/sysaux01.dbf

3                                         /u01/oradata/prod/undotbs01.dbf

4                                         /u01/oradata/prod/users01.dbf

5                                         /u01/oradata/prod/example01.dbf

SYS@prod>select file#,checkpoint_change# from v$datafile_header;

FILE# CHECKPOINT_CHANGE#
---------- ------------------
1            975649
2            975649
3            0
4            975649
5            975649

确定3号文件损坏

cp /home/oracle/hot_backup/undotbs01.dbf /u01/oradata/prod/

recovere datafile 3;auto

alter database open;

4.当前日志,介质损坏

create table t2(id int);

insert into t2 values(100);

commit;

alter system archive log current;

insert into t2 values(200);

commit;

select * from scott.t2;

select group#,sequence#,status from v$log;

select GROUP#,MEMBER from v$logfile;

查出当前的日志是组号是1对应的redo01.log

模拟 rm -rf /u01/oradata/prod/redo01.log

shutdown abort

startup

数据库装载完毕。
ORA-00313: 无法打开日志组 1 (用于线程 1) 的成员 ORA-00312:
联机日志 1 线程 1: ‘/u01/oradata/prod/redo01.log‘
ORA-27037: 无法获得文件状态 Linux
Error: 2: No such file or directory
Additional information: 3

解决:

cd /u01/oradata/prod/

rm *.dbf

cp /home/oracle/hot_backup/*.dbf ./

startup

recover database until cancel;auto

recover database until cancel;cancel

alter database open resetlogs;

select * from scott.t1;

ID
----------
100

5.控制文件损坏

rm -rf /u01/oradata/prod/control01.ctl

rm -rf /u01/flash_recovery_area/prod/control02.ctl

shutdown abort

startup

ORA-00205: ?????????, ??????, ???????

select status from v$instance;

解决:

cp /home/oracle/control01.ctl /u01/oradata/prod/

cp /home/oracle/control02.ctl /u01/flash_recovery_area/prod/

recover database using backup controlfile;auto

recover database using backup controlfile;当前的日志

alter database open resetlogs;

 

oracle数据库热备中的备份和恢复及例子

标签:startup   output   日志组   rm -rf   set   value   span   log   挖掘   

人气教程排行