oracle日志备份恢复

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';
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

duanbeibei

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值