oracle日志备份恢复

原创 2015年07月09日 15:55:20

1. 0级全备

备份前数据

SQL> select * from duanbb.t1;

        ID NAME
---------- --------------------------------------------------
         1 111

rman全备

RMAN> backup incremental level 0 database;

Starting backup at 09-JUL-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=63 device type=DISK
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/home/oracle11/app/oracle11/oradata/orcl/sysaux01.dbf
input datafile file number=00001 name=/home/oracle11/app/oracle11/oradata/orcl/system01.dbf
input datafile file number=00003 name=/home/oracle11/app/oracle11/oradata/orcl/undotbs01.dbf
input datafile file number=00004 name=/home/oracle11/app/oracle11/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 09-JUL-15
channel ORA_DISK_1: finished piece 1 at 09-JUL-15
piece handle=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_nnnd0_TAG20150709T022947_bsw56w9p_.bkp tag=TAG20150709T022947 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 09-JUL-15
channel ORA_DISK_1: finished piece 1 at 09-JUL-15
piece handle=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_ncsn0_TAG20150709T022947_bsw58yp1_.bkp tag=TAG20150709T022947 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 09-JUL-15

2. 插入一条数据,进行日志备份

SQL> insert into duanbb.t1 values(2, '222');

1 row created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL> alter system checkpoint;

SQL> select * from duanbb.t1;

        ID NAME
---------- --------------------------------------------------
         1 111
         2 222

RMAN> backup archivelog all delete input;

Starting backup at 09-JUL-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=473 STAMP=884557194
input archived log thread=1 sequence=4 RECID=474 STAMP=884559659
input archived log thread=1 sequence=5 RECID=475 STAMP=884568650
input archived log thread=1 sequence=6 RECID=476 STAMP=884571491
input archived log thread=1 sequence=7 RECID=477 STAMP=884572546
input archived log thread=1 sequence=8 RECID=478 STAMP=884572648
channel ORA_DISK_1: starting piece 1 at 09-JUL-15
channel ORA_DISK_1: finished piece 1 at 09-JUL-15
piece handle=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_annnn_TAG20150709T023728_bsw5o8w2_.bkp tag=TAG20150709T023728 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_08/o1_mf_1_3_bsvpl9xj_.arc RECID=473 STAMP=884557194
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_08/o1_mf_1_4_bsvrzcfm_.arc RECID=474 STAMP=884559659
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_5_bsw1rb2n_.arc RECID=475 STAMP=884568650
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_6_bsw4k3pw_.arc RECID=476 STAMP=884571491
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_7_bsw5l2jy_.arc RECID=477 STAMP=884572546
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_8_bsw5o8fs_.arc RECID=478 STAMP=884572648
Finished backup at 09-JUL-15

3. 再次插入一条数据,备份日志

SQL> insert into duanbb.t1 values(3, '333');

1 row created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL> alter system checkpoint;

RMAN> backup archivelog all delete input;

Starting backup at 09-JUL-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=9 RECID=479 STAMP=884572860
input archived log thread=1 sequence=10 RECID=480 STAMP=884573073
channel ORA_DISK_1: starting piece 1 at 09-JUL-15
channel ORA_DISK_1: finished piece 1 at 09-JUL-15
piece handle=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_annnn_TAG20150709T024433_bsw62kjx_.bkp tag=TAG20150709T024433 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_9_bsw5vwjy_.arc RECID=479 STAMP=884572860
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_10_bsw62kbg_.arc RECID=480 STAMP=884573073
Finished backup at 09-JUL-15


三次备份生成的文件:

第一次:全备
  o1_mf_nnnd0_TAG20150709T022947_bsw56w9p_.bkp
  o1_mf_ncsn0_TAG20150709T022947_bsw58yp1_.bkp

第二次:日志  
  o1_mf_annnn_TAG20150709T023728_bsw5o8w2_.bkp

第三次: 日志    
  o1_mf_annnn_TAG20150709T024433_bsw62kjx_.bkp


4. 完全恢复(自动恢复到最新状态)

RMAN> startup mount

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area    1221992448 bytes

Fixed Size                     1336176 bytes
Variable Size                939527312 bytes
Database Buffers             268435456 bytes
Redo Buffers                  12693504 bytes
RMAN> run {
2>   allocate channel c1 type disk;
3>   restore database;
4>   recover database;
5>   sql 'alter database open';
6> }

allocated channel: c1
channel c1: SID=63 device type=DISK

Starting restore at 09-JUL-15

channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00001 to /home/oracle11/app/oracle11/oradata/orcl/system01.dbf
channel c1: restoring datafile 00002 to /home/oracle11/app/oracle11/oradata/orcl/sysaux01.dbf
channel c1: restoring datafile 00003 to /home/oracle11/app/oracle11/oradata/orcl/undotbs01.dbf
channel c1: restoring datafile 00004 to /home/oracle11/app/oracle11/oradata/orcl/users01.dbf
channel c1: reading from backup piece /home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_nnnd0_TAG20150709T022947_bsw56w9p_.bkp
channel c1: piece handle=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_nnnd0_TAG20150709T022947_bsw56w9p_.bkp tag=TAG20150709T022947
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:36
Finished restore at 09-JUL-15

Starting recover at 09-JUL-15

starting media recovery

channel c1: starting archived log restore to default destination
channel c1: restoring archived log
archived log thread=1 sequence=7
channel c1: restoring archived log
archived log thread=1 sequence=8
channel c1: reading from backup piece /home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_annnn_TAG20150709T023728_bsw5o8w2_.bkp
channel c1: piece handle=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_annnn_TAG20150709T023728_bsw5o8w2_.bkp tag=TAG20150709T023728
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:01
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_7_bsw6gt1l_.arc thread=1 sequence=7
channel default: deleting archived log(s)
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_7_bsw6gt1l_.arc RECID=482 STAMP=884573466
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_8_bsw6gt1s_.arc thread=1 sequence=8
channel default: deleting archived log(s)
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_8_bsw6gt1s_.arc RECID=481 STAMP=884573466
media recovery complete, elapsed time: 00:00:01
channel c1: starting archived log restore to default destination
channel c1: restoring archived log
archived log thread=1 sequence=9
channel c1: restoring archived log
archived log thread=1 sequence=10
channel c1: reading from backup piece /home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_annnn_TAG20150709T024433_bsw62kjx_.bkp
channel c1: piece handle=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_annnn_TAG20150709T024433_bsw62kjx_.bkp tag=TAG20150709T024433
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:01
channel default: deleting archived log(s)
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_9_bsw6gwgm_.arc RECID=483 STAMP=884573468
channel default: deleting archived log(s)
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_10_bsw6gwgq_.arc RECID=484 STAMP=884573468
Finished recover at 09-JUL-15

sql statement: alter database open
released channel: c1
还原后的数据

SQL> select * from duanbb.t1;

        ID NAME
---------- --------------------------------------------------
         1 111
         2 222
         3 333

5. 按时间点恢复

比如不想恢复“3 333”这条数据,那么只需要恢复到备份2的时间点即可

通过备份出的文件名“o1_mf_annnn_TAG20150709T023728_bsw5o8w2_.bkp”提取时间戳"2015-07-09 02:37:28"

RMAN> run {
2>   allocate channel c1 type disk;
3>   SET UNTIL TIME "to_date('2015-07-09 02:37:28','yyyy-mm-dd hh24:mi:ss')";
4>   restore database;
5>   recover database;
6>   sql 'alter database open resetlogs';
7> }

allocated channel: c1
channel c1: SID=63 device type=DISK

executing command: SET until clause

Starting restore at 09-JUL-15

channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00001 to /home/oracle11/app/oracle11/oradata/orcl/system01.dbf
channel c1: restoring datafile 00002 to /home/oracle11/app/oracle11/oradata/orcl/sysaux01.dbf
channel c1: restoring datafile 00003 to /home/oracle11/app/oracle11/oradata/orcl/undotbs01.dbf
channel c1: restoring datafile 00004 to /home/oracle11/app/oracle11/oradata/orcl/users01.dbf
channel c1: reading from backup piece /home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_nnnd0_TAG20150709T022947_bsw56w9p_.bkp
channel c1: piece handle=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_nnnd0_TAG20150709T022947_bsw56w9p_.bkp tag=TAG20150709T022947
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:45
Finished restore at 09-JUL-15

Starting recover at 09-JUL-15

starting media recovery

channel c1: starting archived log restore to default destination
channel c1: restoring archived log
archived log thread=1 sequence=7
channel c1: restoring archived log
archived log thread=1 sequence=8
channel c1: reading from backup piece /home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_annnn_TAG20150709T023728_bsw5o8w2_.bkp
channel c1: piece handle=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/backupset/2015_07_09/o1_mf_annnn_TAG20150709T023728_bsw5o8w2_.bkp tag=TAG20150709T023728
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:01
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_7_bswfr68o_.arc thread=1 sequence=7
channel default: deleting archived log(s)
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_7_bswfr68o_.arc RECID=492 STAMP=884580934
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_8_bswfr69b_.arc thread=1 sequence=8
channel default: deleting archived log(s)
archived log file name=/home/oracle11/app/oracle11/flash_recovery_area/ORCL/archivelog/2015_07_09/o1_mf_1_8_bswfr69b_.arc RECID=491 STAMP=884580934
media recovery complete, elapsed time: 00:00:00
Finished recover at 09-JUL-15

sql statement: alter database open resetlogs
released channel: c1
恢复后的数据

SQL> select * from duanbb.t1;

        ID NAME
---------- --------------------------------------------------
         1 111
         2 222


总结:

1. 0级全备

backup incremental level 0 database;

2. 日志备份

backup archivelog all delete input;

3. 完全恢复

run {
  allocate channel c1 type disk;
  restore database;
  recover database;
  sql 'alter database open';
}

4. 不完全恢复(按时间点)

run {
  allocate channel c1 type disk;
  SET UNTIL TIME "to_date('2015-07-09 02:37:28','yyyy-mm-dd hh24:mi:ss')";
  restore database;
  recover database;
  sql 'alter database open resetlogs';
}



相关文章推荐

oracle导出数据,备份及恢复数据,及数据库日志文件的查看

以salary为例,在PLSQL Developer中操作 1.导出salary表的数据:将 salary 表的数据以 insert 语句的方式导出                        ...

Oracle数据库日志存放位置

1,默认情况下,oracle的日志文件记录在$ORACLE/rdbms/log目录下 [oracle@oracle log]$ pwd /home/oracle/oracle/product/10...

Oracle11g日志查看方法

 Oracle11日志查看方法  现象描述:  oracle日常维护中经常需要检查alert告警日志,查看数据库是否有问题。  原因分析:  oracle11g修改了日志系统,不在使用oracle9的...

oracle 如何查看日志

Oracle日志查看 一.Oracle日志的路径: 登录:sqlplus "/as sysdba" 查看路径:SQL> select * from v$logfile; SQL> select...

oracle学习笔记 Oracle日志原理剖析

oracle学习笔记  Oracle日志原理剖析 一)一致性和性能 日志是所有数据库的一个很核心的内容很重要 它关系到数据库的数据的一致性 目前大家在使用的我们可看到的有几个数据库 有oracle、s...

第十讲--Oracle日志原理剖析

日志关系到数据一致性,日志和性能没有多大关系。 Oracle的日志是严格按照buffer cache里面buffer的改变时间去记录的。 Oracle怎么记录buffer的改变呢? 1.    ...

Oracle-日志详解(运行模式、分类)

Oracle-日志详解(运行模式、分类) OracleSQL ServerSQL脚本活动  一、Oracle日志分类  分三大类: Alert log files--警报日志,T...

Oracle日志查看

Oracle日志查看 一.Oracle日志的路径: 登录:sqlplus "/as sysdba" 查看路径:SQL> select * from v$logfile; SQL> select *...

Oracle 11g Alert log 文件位置的问题

装了oracle 11g的玩了一下,有点问题,想看一下log日志,找了半天才找到,原来11g的alert log 做了变动,从 Oracle 11g 开始,Oracle 数据库以XML与传统的文本两种...

oracle学习笔记(三)之检查Oracle的告警日志文件

作为一个 DBA,或者哪怕仅仅是和 Oracle 数据库打交道的技术人员,你都必须知道告警日志是什么,在何处。 而对于 DBA来说,实时的监控数据库的告警日志是必须进行的工作,监控并且应该根据不同的严...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:oracle日志备份恢复
举报原因:
原因补充:

(最多只允许输入30个字)