数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

完整的oracle rman备份恢复的例子


发布日期:2021年03月24日
 
完整的oracle rman备份恢复的例子

建rman库作为repository

$more createrman_dbsh

set echo on

spool makedblog

create database rman

datafile /export/home/oracle/oradata/rman_data/systemdbf size m autoextend

on next K

logfile /export/home/oracle/oradata/rman_data/redolog SIZE M

/export/home/oracle/oradata/rman_data/redolog SIZE M

maxdatafiles

maxinstances

maxlogfiles

character set USASCII

national character set USASCII

;

disconnect

spool off

exit

@/export/home/oracle//rdbms/admin/catalogsql;

REM ********** ALTER SYSTEM TABLESPACE *********

ALTER TABLESPACE SYSTEM

DEFAULT STORAGE ( INITIAL K NEXT K MINEXTENTS MAXEXTENTS UNLIMITED PCTINCR

EASE );

ALTER TABLESPACE SYSTEM

MINIMUM EXTENT K;

REM ********** TABLESPACE FOR ROLLBACK **********

CREATE TABLESPACE RBS DATAFILE /export/home/oracle/oradata/rman_data/rbsdbf s

ize m

AUTOEXTEND ON NEXT K

MINIMUM EXTENT K

DEFAULT STORAGE ( INITIAL K NEXT K MINEXTENTS MAXEXTENTS UNLIMITED PC

TINCREASE );

REM ********** TABLESPACE FOR TEMPORARY **********

CREATE TABLESPACE TEMP DATAFILE /export/home/oracle/oradata/rman_data/tempdbf

size m

AUTOEXTEND ON NEXT K

MINIMUM EXTENT K

DEFAULT STORAGE ( INITIAL K NEXT K MINEXTENTS MAXEXTENTS UNLIMITED PCTINCR

EASE ) TEMPORARY;

REM **** Creating four rollback segments ****************

CREATE PUBLIC ROLLBACK SEGMENT RBS_ TABLESPACE RBS

STORAGE ( OPTIMAL K );

ALTER ROLLBACK SEGMENT RBS_ ONLINE;

REM **** SYS and SYSTEM users ****************

alter user sys temporary tablespace TEMP;

alter user system temporary tablespace TEMP;

disconnect

spool off

exit

$more createrman_dbsh

spool crdblog

@/export/home/oracle//rdbms/admin/catprocsql

@/export/home/oracle//rdbms/admin/cathssql

@/export/home/oracle//rdbms/admin/otrcsvrsql

connect system/manager

@/export/home/oracle//sqlplus/admin/pupbldsql

disconnect

spool off

exit

建repository存放的表空间和rman用户

$more createrman_dbsh

connect internal

create tablespace rman_ts

datafile /export/home/oracle/oradata/rman_data/rman_tsdbf

size M default storage (initial K next K pctincrease );

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;

建catalog注册目标数据库

$more createrman_dbsh

rman catalog rman_hainan/rman_hainan@rman msglog=rmanlog

create catalog ;

exit;

rman target sys/oracle@db

connect catalog rman_hainan/rman_hainan@rman

register database;

exit;

可以开始做备份了

做全备

$more rmanshell

/export/home/oracle/profile

rman rcvcat rman_hainan/rman_hainan@rman target / cmdfile /export/home/oracle/ba

ckup_levelrcv log /export/home/oracle/backuplog

$more backup_levelrcv

resync catalog;

run {

allocate channel t type disk;

backup

incremental level

skip inaccessible

tag hot_db_bk_level

filesperset

format /export/home/oracle/bk_%s_%p_%tbk

(database);

sql alter system archive log current;

backup

filesperset

format /export/home/oracle/a_%s_%p_%tac

(archivelog all delete input);

backup

format /export/home/oracle/df_t%t_s%s_p%pct

current controlfile ;

}

做增备

$more rmanshell

rman rcvcat rman_hainan/rman_hainan@rman target / cmdfile backup_levelrcv log

backuplog

$more backup_levelrcv

resync catalog;

run {

allocate channel t type disk;

backup

incremental level

skip inaccessible

tag hot_db_bk_level

filesperset

format bk_%s_%p_%tbk

(database);

sql alter system archive log current;

backup

filesperset

format a_%s_%p_%tac

(archivelog all delete input);

backup current controlfile;

}

删除旧的全备

$rman rcvcat rman_hainan/rman_hainan@rman target /

Recovery Manager: Release Production

RMAN: connected to target database: TEST (DBID=)

RMAN: connected to recovery catalog database

RMAN> list backupset;

RMAN: compiling command: list

List of Backup Sets

Key Recid Stamp LV Set Stamp Set Count Completion Time

JUN

根据key来删除旧的备份

RMAN> allocate channel for maintenance type disk;

RMAN> change backupset delete; THIS IS THE COMMAND TO REMOVE THE ENTRY & OS FILE

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

恢复

) 将数据库启动到nomount状态

$svrmgrl

Oracle Server Manager Release Production

Copyright (c) Oracle Corporation All Rights Reserved

Oraclei Enterprise Edition Release bit Production

With the Partitioning option

JServer Release Production

SVRMGR> connect internal

Connected

SVRMGR> startup nomount;

ORACLE instance started

Total System Global Area bytes

Fixed Size bytes

Variable Size bytes

Database Buffers bytes

Redo Buffers bytes

SVRMGR> exit

Server Manager complete

) 恢复控制文件

$rman rcvcat rman_hainan/rman_hainan@rman target /

Recovery Manager: Release Production

RMAN: connected to target database: test (not mounted)

RMAN: connected to recovery catalog database

RMAN> run {

> allocate channel d type disk;

> restore controlfile;

> release channel d;

> }

) 恢复数据文件

RMAN> run {

> allocate channel d type disk;

> sql alter database mount;

> restore datafile ;

> restore datafile ;

> restore datafile ;

> restore datafile ;

> release channel d;

> }

) 恢复日志文件

RMAN> run {

> set archivelog destination to /export/home/oracle/admin/test/arch;

> allocate channel d type disk;

> restore archivelog all;

> release channel d;

> }

会把所有的日志文件恢复

) 根据日志做recover

$svrmgrl

Oracle Server Manager Release Production

Copyright (c) Oracle Corporation All Rights Reserved

Oraclei Enterprise Edition Release bit Production

With the Partitioning option

JServer Release Production

SVRMGR> connect internal

Connected

SVRMGR> recover database using backup controlfile until cancel;

ORA: change generated at // :: needed for thread

ORA: suggestion : /export/home/oracle/admin/test

上一篇:Linux下Oracle10

下一篇:Oracle rac安装过程详解(二)