`
lilei821029
  • 浏览: 25624 次
  • 性别: Icon_minigender_1
  • 来自: 济南
最近访客 更多访客>>
社区版块
存档分类
最新评论

完整的oracle rman备份恢复的例子(转)

阅读更多
注:转这个文章的原因是rman很重要,可是到目前为止我还不会用这个玩意儿。

完整的oracle rman备份恢复的例子
 
作者:zhumy
1、 建rman库作为repository
$more createrman_db1.sh
set echo on
spool makedb1.log
create database rman
datafile '/export/home/oracle/oradata/rman_data/system.dbf' size 50m autoextend
on next 640K
logfile '/export/home/oracle/oradata/rman_data/redo0101.log' SIZE 10M,
'/export/home/oracle/oradata/rman_data/redo0201.log' SIZE 10M
maxdatafiles 30
maxinstances 8
maxlogfiles 64
character set US7ASCII
national character set US7ASCII
;
disconnect
spool off
exit

@/export/home/oracle/8.1.6/rdbms/admin/catalog.sql;

REM ********** ALTER SYSTEM TABLESPACE *********
ALTER TABLESPACE SYSTEM
DEFAULT STORAGE ( INITIAL 64K NEXT 64K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCR
EASE 50);
ALTER TABLESPACE SYSTEM
MINIMUM EXTENT 64K;

REM ********** TABLESPACE FOR ROLLBACK **********
CREATE TABLESPACE RBS DATAFILE '/export/home/oracle/oradata/rman_data/rbs.dbf' s
ize 50m
AUTOEXTEND ON NEXT 512K
MINIMUM EXTENT 512K
DEFAULT STORAGE ( INITIAL 512K NEXT 512K MINEXTENTS 10 MAXEXTENTS UNLIMITED PC
TINCREASE 0 );

REM ********** TABLESPACE FOR TEMPORARY **********
CREATE TABLESPACE TEMP DATAFILE '/export/home/oracle/oradata/rman_data/temp.dbf'
size 50m
AUTOEXTEND ON NEXT 64K
MINIMUM EXTENT 64K
DEFAULT STORAGE ( INITIAL 64K NEXT 64K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCR
EASE 0) TEMPORARY;

REM **** Creating four rollback segments ****************
CREATE PUBLIC ROLLBACK SEGMENT RBS_0 TABLESPACE RBS
STORAGE ( OPTIMAL 64000K );
ALTER ROLLBACK SEGMENT "RBS_0" ONLINE;


REM **** SYS and SYSTEM users ****************
alter user sys temporary tablespace TEMP;
alter user system temporary tablespace TEMP;
disconnect
spool off
exit

$more createrman_db3.sh
spool crdb3.log
@/export/home/oracle/8.1.6/rdbms/admin/catproc.sql
@/export/home/oracle/8.1.6/rdbms/admin/caths.sql
@/export/home/oracle/8.1.6/rdbms/admin/otrcsvr.sql
connect system/manager
@/export/home/oracle/8.1.6/sqlplus/admin/pupbld.sql

disconnect
spool off
exit

2、建repository存放的表空间和rman用户
$more createrman_db4.sh
connect internal
create tablespace rman_ts
datafile '/export/home/oracle/oradata/rman_data/rman_ts.dbf'
size 20M default storage (initial 100K next 100K pctincrease 0);
create user rman_hainan identified by rman_hainan
temporary tablespace TEMP
default tablespace rman_ts quota unlimited on
rman_ts;
grant recovery_catalog_owner to rman_hainan;
grant connect ,resource to rman_hainan;

3、建catalog,注册目标数据库
$more createrman_db5.sh
rman catalog rman_hainan/rman_hainan@rman msglog=rman.log
create catalog ;
exit;
rman target sys/oracle@db1
connect catalog rman_hainan/rman_hainan@rman
register database;
exit;

4、可以开始做备份了。
5、做全备
$more rmanshell
. /export/home/oracle/.profile
rman rcvcat rman_hainan/rman_hainan@rman target / cmdfile /export/home/oracle/ba
ckup_level0.rcv log /export/home/oracle/backup.log

$more backup_level0.rcv
resync catalog;
run {
allocate channel t1 type disk;
backup
incremental level 0
skip inaccessible
tag hot_db_bk_level0
filesperset 3
format '/export/home/oracle/bk_%s_%p_%t.bk'
(database);
sql 'alter system archive log current';
backup
filesperset 10
format '/export/home/oracle/a1_%s_%p_%t.ac'
(archivelog all delete input);
backup
format '/export/home/oracle/df_t%t_s%s_p%p.ct'
current controlfile ;
}

6、做增备
$more rmanshell1
rman rcvcat rman_hainan/rman_hainan@rman target / cmdfile backup_level1.rcv log
backup.log

$more backup_level1.rcv
resync catalog;
run {
allocate channel t1 type disk;
backup
incremental level 1
skip inaccessible
tag hot_db_bk_level1
filesperset 3
format 'bk_%s_%p_%t.bk1'
(database);
sql 'alter system archive log current';
backup
filesperset 10
format 'a1_%s_%p_%t.ac1'
(archivelog all delete input);
backup current controlfile;
}

1、 删除旧的全备
$rman rcvcat rman_hainan/rman_hainan@rman target /

Recovery Manager: Release 8.1.6.0.0 - Production

RMAN-06005: connected to target database: TEST (DBID=1692992254)
RMAN-06008: connected to recovery catalog database

RMAN> list backupset;

RMAN-03022: compiling command: list

List of Backup Sets
Key Recid Stamp LV Set Stamp Set Count Completion Time
------- ---------- ---------- -- ---------- ---------- ----------------------
38 145 399987408 0 399987406 153 11-JUN-00

根据key来删除旧的备份。

RMAN> allocate channel for maintenance type disk;
RMAN> change backupset 169 delete; ----------THIS IS THE COMMAND TO REMOVE THE ENTRY & OS FILE

做完后可以看到list backupset和操作系统的文件都没有了。

2、 恢复
(1) 将数据库启动到nomount状态:
$svrmgrl

Oracle Server Manager Release 3.1.6.0.0 - Production

Copyright (c) 1997, 1999, Oracle Corporation. All Rights Reserved.

Oracle8i Enterprise Edition Release 8.1.6.0.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production

SVRMGR> connect internal
Connected.
SVRMGR> startup nomount;
ORACLE instance started.
Total System Global Area 339275684 bytes
Fixed Size 94116 bytes
Variable Size 318685184 bytes
Database Buffers 16384000 bytes
Redo Buffers 4112384 bytes
SVRMGR> exit
Server Manager complete.
(2) 恢复控制文件:
$rman rcvcat rman_hainan/rman_hainan@rman target /

Recovery Manager: Release 8.1.6.0.0 - Production

RMAN-06006: connected to target database: test (not mounted)
RMAN-06008: connected to recovery catalog database

RMAN> run {
2> allocate channel d1 type disk;
3> restore controlfile;
4> release channel d1;
5> }

(3) 恢复数据文件

RMAN> run {
2> allocate channel d1 type disk;
3> sql "alter database mount";
4> restore datafile 1;
5> restore datafile 2;
6> restore datafile 3;
7> restore datafile 4;
8> release channel d1;
9> }

(4) 恢复日志文件

RMAN> run {
2> set archivelog destination to '/export/home/oracle/admin/test/arch';
3> allocate channel d1 type disk;
4> restore archivelog all;
5> release channel d1;
6> }
会把所有的日志文件恢复。

(5) 根据日志做recover
$svrmgrl

Oracle Server Manager Release 3.1.6.0.0 - Production

Copyright (c) 1997, 1999, Oracle Corporation. All Rights Reserved.

Oracle8i Enterprise Edition Release 8.1.6.0.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production

SVRMGR> connect internal
Connected.
SVRMGR> recover database using backup controlfile until cancel;
ORA-00279: change 51054 generated at 06/11/2000 11:38:37 needed for thread 1
ORA-00289: suggestion : /export/home/oracle/admin/test/arch/arch_1_3.arc
ORA-00280: change 51054 for thread 1 is in sequence #3
Specify log: {=suggested | filename | AUTO | CANCEL}
Log applied.
ORA-00279: change 51058 generated at 06/11/2000 11:38:44 needed for thread 1
ORA-00289: suggestion : /export/home/oracle/admin/test/arch/arch_1_4.arc
ORA-00280: change 51058 for thread 1 is in sequence #4
ORA-00278: log file '/export/home/oracle/admin/test/arch/arch_1_3.arc' no longer
needed for this recovery
Specify log: {=suggested | filename | AUTO | CANCEL}

Log applied.
ORA-00279: change 51074 generated at 06/11/2000 11:40:20 needed for thread 1
ORA-00289: suggestion : /export/home/oracle/admin/test/arch/arch_1_5.arc
ORA-00280: change 51074 for thread 1 is in sequence #5
ORA-00278: log file '/export/home/oracle/admin/test/arch/arch_1_4.arc' no longer
needed for this recovery
Specify log: {=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
SVRMGR> alter database open resetlogs;
Statement processed.
恢复完成。
SVRMGR> select table_name from user_tables;
TABLE_NAME
------------------------------
BONUS
DEPT
EMP
SALGRADE
TEST
TEST_ZMY
ZMY
ZMY_DEPT
ZMY_EMP
9 rows selected.
可以检查看到,所有的都恢复了,包括全备份后的事务。(只要有归档日志,都可以恢复)。

3、 恢复后rman数据库的同步
$rman rcvcat rman_hainan/rman_hainan@rman target /

Recovery Manager: Release 8.1.6.0.0 - Production

RMAN-06005: connected to target database: TEST (DBID=1692992254)
RMAN-06008: connected to recovery catalog database

RMAN> reset database;

RMAN-03022: compiling command: reset
RMAN-03023: executing command: reset
RMAN-08006: database registered in recovery catalog
RMAN-03023: executing command: full resync
RMAN-08029: snapshot controlfile name set to default value: ?/dbs/snapcf_@.f
RMAN-08002: starting full resync of recovery catalog
RMAN-08004: full resync complete

分享到:
评论

相关推荐

    ORACLE 数据库 备份和恢复的 案例 例子 rman

    ORACLE 数据库 备份和恢复的 案例 例子 rman,

    oracle备份恢复之一步一步学RMAN完整版

    oracle系统管理员详细总结的rman备份的完整过程,例子加详解,很好的资源。

    rman命令使用集

    小资料,集中汇总,对于oracle备份恢复工具rman是一总结资料,便于使用查阅,都有例子引用,比较清楚

    RMAN 初学者指南

    RMAN(Recovery Manager)是DBA的一个重要工具,用于备份、还原和恢复oracle数据库,前一段时间有网友找我要,可惜没时间,趁这两天出差在外没什么事,就 写了一下,供初学的朋友参考。本文将介绍RMAN 的基本操作,更...

    rman_study

    RMAN(Recovery Manager)是DBA的一个重要工具,用于备份、还原和恢复oracle数据库,前一段时间有网友找我要,可惜没时间,趁这两天出差在外没什么事,就写了一下,供初学的朋友参考。本文将介绍RMAN 的基本操作,更多...

    构建最高可用Oracle数据库系统 Oracle 11gR2 RAC管理、维护与性能优化

    12.7其他备份恢复技术 12.7.1用户管理备份 12.7.2导入导出工具数据泵 12.7.3跨平台数据迁移 12.7.4可传输表空间 12.7.5使用RMAN工具复制数据库 12.8本章小结 第13章 RAC恢复 13.1恢复技术基础 13.1.1恢复...

    图解Oracle数据库小版本升级过程

    如果是从10.1.0.1.0 升级到10.2.0.4.0或者从oracle 10g升级到11g就叫大版本升级,在这种情况下通常是先将当前数据库通过EXPDP(exp)或者RMAN做全备份,升级数据库软件,然后再用IMPDP(imp)或者RMAN恢复到新的数据库。...

    Oracle 11g数据库指南-迷你版电子书

    第四部分介绍了数据库的备份与恢复,其中对RMAN进行了重点介绍。 本书不仅可以作为Oracle数据库技术人员的参考手册,还可以作为培训中心的培训教材。 作者:刘宪军 男,IBM全球认证讲师,1997年毕业于西北大学计算机...

    最全的oracle常用命令大全.txt

    六、ORACLE逻辑备份的SH文件 完全备份的SH文件:exp_comp.sh rq=` date +"%m%d" ` su - oracle -c "exp system/manager full=y inctype=complete file=/oracle/export/db_comp$rq.dmp" 累计备份的SH文件:exp_...

    记一次Oracle数据恢复过程

    事情的起因是,一个应用升级后,某一个操作导致一个表的几个列...维护人员说,星期五之前的RMAN备份已经被删除了(又是一个备份恢复策略不当地例子),使用基于时间点的恢复也不可能了。剩下的一条路,只有使用log min

    ORACLE9i_优化设计与系统调整

    第一部分 ORACLE系统优化基本知识 23 第1章 ORACLE结构回顾 23 §1.1 Oracle数据库结构 23 §1.1.1 Oracle数据字典 23 §1.1.2 表空间与数据文件 24 §1.1.3 Oracle实例(Instance) 24 §1.2 Oracle文件 26 §1.2.1...

    oracle恢复工具-FY_Recover_Data

    否则会导致服务器RMAN备份失败ORA-19566 超出损坏块限制(切记) truncate原理: ? ? ? ?TRUNCATE不会逐个清除用户数据块上的数据,而仅仅重置数据字典和元数据块上的元数据(如存储段头和扩展段...

    ORACLE之常用FAQ V1.0(整理)

    [Q]丢失一个数据文件,没有备份但是有该数据文件创建以来的归档怎么恢复 30 [Q]联机日志损坏如何恢复 31 [Q]怎么样创建RMAN恢复目录 31 [Q]怎么样在恢复的时候移动数据文件,恢复到别的地点 32 [Q]怎么从备份片...

    oracle数据库经典题目

    29. 下列哪一个命令用来显示RMAN通道的配置信息?( C ) A. LIST B. DISPLAY C.SHOW D.都可以 30. 下列哪一个命令可以用来执行不完全恢复?( B ) A. RESTORE DATABASE UNTIL B. RECOVER DATABASE UNTIL C. ...

Global site tag (gtag.js) - Google Analytics