`
itspace
  • 浏览: 978469 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Oracle备份恢复之利用dbms_backup_restore恢复数据库

阅读更多
进行测试之前先将数据库做全备:
引用
RMAN> run {
2> allocate channel ch00 device type disk;
3> backup database include current controlfile format '/backup/full%t' tag='FULLDB';
4> sql 'alter system archive log current';
5> backup archivelog all format '/backup/arch%t' tag='ARCHIVELOG';
6> release channel ch00;
7> }

allocated channel: ch00
channel ch00: sid=17 devtype=DISK

Starting backup at 20-JAN-10
channel ch00: starting full datafile backupset
channel ch00: specifying datafile(s) in backupset
including current controlfile in backupset
input datafile fno=00001 name=/app/oracle/oradata/ora9i/system01.dbf
input datafile fno=00002 name=/app/oracle/oradata/ora9i/undotbs01.dbf
input datafile fno=00005 name=/app/oracle/oradata/ora9i/example01.dbf
input datafile fno=00011 name=/app/oracle/oradata/ora9i/STREAM01.dbf
input datafile fno=00010 name=/app/oracle/oradata/ora9i/xdb01.dbf
input datafile fno=00006 name=/app/oracle/oradata/ora9i/indx01.dbf
input datafile fno=00009 name=/app/oracle/oradata/ora9i/users01.dbf
input datafile fno=00003 name=/app/oracle/oradata/ora9i/cwmlite01.dbf
input datafile fno=00004 name=/app/oracle/oradata/ora9i/drsys01.dbf
input datafile fno=00007 name=/app/oracle/oradata/ora9i/odm01.dbf
input datafile fno=00008 name=/app/oracle/oradata/ora9i/tools01.dbf
channel ch00: starting piece 1 at 20-JAN-10
channel ch00: finished piece 1 at 20-JAN-10
piece handle=/backup/full708756233 comment=NONE
channel ch00: backup set complete, elapsed time: 00:02:26
Finished backup at 20-JAN-10

Starting Control File and SPFILE Autobackup at 20-JAN-10
piece handle=/app/oracle/product/9.0.2/dbs/c-2494723682-20100120-00 comment=NONE
Finished Control File and SPFILE Autobackup at 20-JAN-10

sql statement: alter system archive log current

Starting backup at 20-JAN-10
current log archived
channel ch00: starting archive log backupset
channel ch00: specifying archive log(s) in backup set
input archive log thread=1 sequence=1 recid=254 stamp=708756150
input archive log thread=1 sequence=2 recid=255 stamp=708756383
input archive log thread=1 sequence=3 recid=256 stamp=708756383
channel ch00: starting piece 1 at 20-JAN-10
channel ch00: finished piece 1 at 20-JAN-10
piece handle=/backup/arch708756383 comment=NONE
channel ch00: backup set complete, elapsed time: 00:00:02
Finished backup at 20-JAN-10

Starting Control File and SPFILE Autobackup at 20-JAN-10
piece handle=/app/oracle/product/9.0.2/dbs/c-2494723682-20100120-01 comment=NONE
Finished Control File and SPFILE Autobackup at 20-JAN-10

released channel: ch00

假设现在数据库异常宕机
引用
SQL> shutdown abort
ORACLE instance shut down

启动数据库至nomount状态
引用
SQL> startup nomount
ORACLE instance started.

Total System Global Area 1125193868 bytes
Fixed Size                   452748 bytes
Variable Size             335544320 bytes
Database Buffers          788529152 bytes
Redo Buffers                 667648 bytes

1、利用dbms_backup_restore恢复控制文件
引用

SQL> DECLARE
  2  devtype varchar2(256);
  3  done boolean;
  4  BEGIN
  5  devtype := dbms_backup_restore.DeviceAllocate(type => '',ident => 'testctl');
  6  dbms_backup_restore.RestoresetdataFile;
  7  dbms_backup_restore.RestoreControlFileto('/app/oracle/oradata/ora9i/control01.ctl');
  8  dbms_backup_restore.RestoreBackupPiece('/backup/full708756233',done => done);
  9  dbms_backup_restore.RestoresetdataFile;
10  dbms_backup_restore.RestoreControlFileto('/app/oracle/oradata/ora9i/control02.ctl');
11  dbms_backup_restore.RestoreBackupPiece('/backup/full708756233',done => done);
12  dbms_backup_restore.RestoresetdataFile;
13  dbms_backup_restore.RestoreControlFileto('/app/oracle/oradata/ora9i/control03.ctl');
14  dbms_backup_restore.RestoreBackupPiece('/backup/full708756233',done => done);
15  dbms_backup_restore.DeviceDeallocate;
16  END;
17  /

PL/SQL procedure successfully completed.

当然也已可用rman进行控制文件恢复
引用
RMAN> restore controlfile from '/app/oracle/product/9.0.2/dbs/c-2494723682-20100120-00';

Starting restore at 20-JAN-10

using channel ORA_DISK_1
channel ORA_DISK_1: restoring controlfile
channel ORA_DISK_1: restore complete
replicating controlfile
input filename=/app/oracle/oradata/ora9i/control01.ctl
output filename=/app/oracle/oradata/ora9i/control02.ctl
output filename=/app/oracle/oradata/ora9i/control03.ctl
Finished restore at 20-JAN-10


2、利用dbms_backup_restore恢复数据文件
引用
SQL> DECLARE
  2  devtype varchar2(256);
  3  done boolean;
  4  BEGIN
  5  devtype := dbms_backup_restore.DeviceAllocate (type => '',ident => 'testdatafile');
  6  dbms_backup_restore.RestoreSetDatafile;
  7  dbms_backup_restore.RestoreDatafileTo(dfnumber => 1,toname => '/app/oracle/oradata/ora9i/system01.dbf');
  8  dbms_backup_restore.RestoreDatafileTo(dfnumber => 2,toname => '/app/oracle/oradata/ora9i/undotbs01.dbf');
  9  dbms_backup_restore.RestoreBackupPiece(done => done,handle => '/backup/full708756233', params => null);
10  dbms_backup_restore.DeviceDeallocate;
11  END;
12  /



PL/SQL procedure successfully completed.

3、利用dbms_backup_restore恢复归档日志
引用
SQL> DECLARE
  2  devtype varchar2(256);
  3  done boolean;
  4  BEGIN
  5  devtype := dbms_backup_restore.DeviceAllocate (type => '',ident => 'testarchlog');
  6  dbms_backup_restore.RestoreSetArchivedLog(destination=>'/app/oracle/product/9.0.2/dbs/arch');
  7  dbms_backup_restore.RestoreArchivedLog(thread=>1,sequence=>1);
  8  dbms_backup_restore.RestoreArchivedLog(thread=>1,sequence=>2);
  9  dbms_backup_restore.RestoreArchivedLog(thread=>1,sequence=>3);
10  dbms_backup_restore.RestoreBackupPiece(done => done,handle => '/backup/arch708756383', params => null);
11  dbms_backup_restore.DeviceDeallocate;
12  END;
13  /

PL/SQL procedure successfully completed.


4、不完全恢复打开数据库
引用
SQL> alter database mount;

Database altered.
SQL> recover database using backup controlfile;
ORA-00279: change 17329956 generated at 01/20/2010 04:43:54 needed for thread 1
ORA-00289: suggestion : /app/oracle/product/9.0.2/dbs/arch/1_2.dbf
ORA-00280: change 17329956 for thread 1 is in sequence #2


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 17330517 generated at 01/20/2010 04:46:23 needed for thread 1
ORA-00289: suggestion : /app/oracle/product/9.0.2/dbs/arch/1_3.dbf
ORA-00280: change 17330517 for thread 1 is in sequence #3
ORA-00278: log file '/app/oracle/product/9.0.2/dbs/arch/1_2.dbf' no longer
needed for this recovery


ORA-00279: change 17330520 generated at 01/20/2010 04:46:23 needed for thread 1
ORA-00289: suggestion : /app/oracle/product/9.0.2/dbs/arch/1_4.dbf
ORA-00280: change 17330520 for thread 1 is in sequence #4
ORA-00278: log file '/app/oracle/product/9.0.2/dbs/arch/1_3.dbf' no longer
needed for this recovery


ORA-00308: cannot open archived log
'/app/oracle/product/9.0.2/dbs/arch/1_4.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 17330520 generated at 01/20/2010 04:46:23 needed for thread 1
ORA-00289: suggestion : /app/oracle/product/9.0.2/dbs/arch/1_4.dbf
ORA-00280: change 17330520 for thread 1 is in sequence #4


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/app/oracle/oradata/ora9i/redo06.log
Log applied.
Media recovery complete.
0
0
分享到:
评论

相关推荐

    Oracle PL/SQL常用47个工具包

    40. **DBMS_BACKUP_RESTORE**: 数据库备份和恢复工具。 41. **DBMS_CRYPTO.HASH**: 创建数据的哈希值,用于验证数据完整性。 42. **DBMS_METADATA.GET_TRANSFORM_PARAM**: 查询当前转换参数设置。 43. **DBMS_...

    oracle rman 恢复攻略

    sys.dbms_backup_restore.restoreBackupPiece(done=&gt;done,handle=&gt;'/opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp',params=&gt;null); sys.dbms_backup_...

    基于RMAN的Oracle数据库备份与恢复机制.pdf

    命令执行器是RMAN的核心组件,负责解释用户输入的控制命令,并将其翻译成PL/SQL指令,通过网络连接目标数据库并将PL/SQL指令传送给数据库实例中的DBMS-BACKUP-RESTORE和DBMS-RCVMAN两个PL/SQL程序包。 目标数据库是...

    oracle四大宝典之3:Oracle备份与恢复

    9. **PL/SQL和SQL命令**:熟练掌握`RESTORE`、`RECOVER`等SQL命令,以及相关的PL/SQL包,如DBMS_RECOVERY,是进行备份恢复操作的基础。 10. **最佳实践**:定期测试恢复过程,确保备份的可用性;合理规划备份存储...

    oracle数据库备份恢复

    ### Oracle数据库备份恢复 #### RMAN(备份与恢复管理器) **RMAN**,即**Recovery Manager**,是Oracle数据库管理系统中的一项重要工具,主要用于数据库的备份与恢复操作。它能够提供高度自动化且功能强大的解决...

    Oralce11g数据库常见内置程序包

    5. **DBMS_BACKUP_RESTORE**:备份和恢复工具。 6. **DBMS_SCHEDULER**:用于创建和管理调度任务。 7. **DBMS_FLASHBACK**:支持闪回查询和恢复操作。 8. **DBMS_AUTO_TASK_ADMIN**:自动化任务管理。 #### 五、DSA...

    Oracle数据库的备份与恢复策略研究

    ### Oracle数据库的备份与恢复策略研究 ...此外,随着技术的发展,Oracle数据库还提供了更多的高级备份工具和技术,例如RMAN(Restore and Recovery Manager),可以帮助用户更高效地进行数据库的备份和恢复工作。

    VB逻辑备份oracle、sqlserver数据库

    可以使用DBMS_BACKUP_RESTORE包或者EXPDP(数据泵导出)命令来进行逻辑备份。VB程序可以构建一个自动化脚本,定时触发这些命令,将数据库表、用户对象、甚至是整个数据库导出为一个或多个文件。同时,程序需要处理...

    oracle恢复工具-FY_Recover_Data

    它是利用Oracle表扫描机制、数据嫁接机制恢复TRUNCATE或者损坏数据的工具包,这个包是由行内有影响力的DBA大师黄炜先生通过PLSQL编写的,再这里再次感谢他的无私技术分享。Fy_Recover_Data去本文附近中下载 好了,...

    数据库坏块(ORA-01578)的解决方法.pdf

    总的来说,解决Oracle数据库的坏块问题需要深入理解数据库的工作原理、故障排查技巧以及如何利用Oracle提供的工具进行修复。这不仅依赖于理论知识,实践经验同样重要,因为每个环境都有其独特性,可能需要定制化的...

    数据库巡检常用命令PLSQL

    4. **备份与恢复**:编写PL/SQL脚本来自动化备份和恢复过程,例如使用`DBMS_BACKUP_RESTORE`包来执行物理备份,或`DBMS_RMAN`包进行RMAN备份。 5. **数据库安全性**:使用`DBA_USERS`、`DBA_ROLES`和`DBA_PRIVS`...

    DAVE Oracle RMAN 学习笔记

    2. **sys.dbms_backup_restore**:用于创建系统调用来执行数据库的备份或恢复操作。 此外,还有一些内核级别的RMAN数据包支持RMAN在不同的数据库状态(如nomount和mount)下运行。 #### 数据块备份概述 1. **数据...

    ORACLE在信息系统应用中的一种备份方案.pdf

    RMAN命令执行器接收用户输入的备份指令,并将其转化为PL/SQL指令,通过网络连接发送给目标数据库实例,由数据库实例中的DBMS_BACKUP_RESTORE和DBMS_RMAN包处理,从而实现备份和恢复操作。恢复目录则是一个独立于目标...

    Oracle 11g rman 异机还原再升级到 12c PDB

    本文档详细记录了从Oracle 11.2.0.4版本数据库通过RMAN工具进行异地备份恢复,并最终升级至12c PDB环境的过程。 #### 数据库版本确认 **源数据库 (11g):** ``` Oracle Database 11g Enterprise Edition Release ...

    logminer总结文档

    - 清除控制文件中的归档日志信息:`EXECUTE SYS.DBMS_BACKUP_RESTORE.RESETCFILESECTION(11);` - **归档日志相关操作** - 手动归档所有日志:`ALTER SYSTEM ARCHIVELOG ALL;` - 归档当前日志:`ALTER SYSTEM ...

    RMAN恢復数据库到指定時間點

    在Oracle数据库管理中,RMAN(Recovery Manager)是一种强大的工具,用于备份、还原和恢复数据库。它提供了多种方式来保护数据免受各种灾难的影响,其中包括将数据库恢复到指定时间点的功能。这种不完全恢复的方法...

    java备份还原数据库

    - **物理还原**:直接替换数据库文件或使用特定的恢复命令(如MySQL的`mysqlimport`或SQL Server的`RESTORE DATABASE`)。 - **逻辑还原**:通过读取备份文件中的SQL语句,使用`java.sql.Statement`执行这些语句来...

    oracle备份

    Oracle数据库是企业级广泛应用的关系型数据库系统,其稳定性和数据安全性是其核心优势之一。为了确保数据在意外情况下的可恢复性,Oracle提供了多种备份策略和技术。本篇将详细讲解Oracle自动备份、定期备份以及如何...

    ORACLE11G新特性

    Oracle 11G 引入了一个重要的新工具——数据恢复顾问(Data Recovery Advisor,简称 DRA),它能够自动诊断并修复数据库中的故障。当遇到物理损坏或逻辑错误时,DRA 可以提供一系列建议来修复问题。例如: 1. **...

Global site tag (gtag.js) - Google Analytics