日期:2014-05-16  浏览次数:20597 次

完整的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@