码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2017-11-13 20:01:09      阅读:172      评论:0      收藏:0      [点我收藏+]

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

手工热备(开库状态)

备份控制文件:

alter database backup controlfile to ‘/u01/oradata/prod/con.bak1‘;

备份数据文件(这里用到pl/sql进行批处理,将查询结果粘贴运行即可)

begin
for i in (select tablespace_name from dba_tablespaces) loop
dbms_output.put_line(‘alter tablespace ‘||i.tablespace_name||‘ begin backup;‘);
for j in (select file_name from dba_data_files where tablespace_name=i.tablespace_name) loop
dbms_output.put_line(‘host cp ‘||j.file_name||‘ /home/oracle/hot_backup‘);
end loop;
dbms_output.put_line(‘alter tablespace ‘||i.tablespace_name||‘ end backup;‘);
end loop;
end;

模拟现场,举例

1.删除emp1表 drop table emp1 purge;(不完全恢复)

模拟:

drop table emp1 purge;

select * from v$log;

alter system switch logfile;

/

解决:

select name from v$archived_log;(可以看到删除的日志条目切换到此归档日志里了)

/u01/flash_recovery_area/PROD/archivelog/2017_08_13/o1_mf_1_6_drzyyodl_.arc
/u01/flash_recovery_area/PROD/archivelog/2017_08_27/o1_mf_1_7_dt4yy16z_.arc
/u01/flash_recovery_area/PROD/archivelog/2017_08_27/o1_mf_1_8_dt4zlzff_.arc
/u01/flash_recovery_area/PROD/archivelog/2017_08_27/o1_mf_1_9_dt4zow6g_.arc
/u01/flash_recovery_area/PROD/archivelog/2017_08_27/o1_mf_1_1_dt5fpkxt_.arc
/u01/flash_recovery_area/PROD/archivelog/2017_11_12/o1_mf_1_2_f0jh6xf2_.arc
/u01/flash_recovery_area/PROD/archivelog/2017_11_12/o1_mf_1_3_f0jk4n4p_.arc
/u01/flash_recovery_area/PROD/archivelog/2017_11_13/o1_mf_1_1_f0lkgyt6_.arc
/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   挖掘   

原文地址:http://www.cnblogs.com/wjmbk/p/7827388.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!