創建
概述
使用RMAN 備份也分catalog 和nocatalog,就是是否使用恢復目錄,如果不使用恢復目錄,那么就是用control file作為catalog,每一次備份都要往控制文件里面寫好多備份信息,控制文件里面會有越來越多的備份信息。因此,當使用rman nocatalog方式備份時,備份controlfile是非常重要的。 如果使用catalog模式,就需要句需要創建catalog目錄。 當庫比較多時,使用catalog也是比較方便的。
(oracle 使用catalog 來進行備份的話就需要先創建個catalog用戶)
Catalog 則必須要首先要創建目錄備份數據庫,建立恢復目錄。另外,由於nocatalog時利用controlfile存放備份信息,建議將Oracle參數文件中的CONTROL_FILE_RECORD_KEEP_TIME值加大(缺省為7天), 該參數在$ORACLE_HOME/dbs/initSID.ora中(9i后也可能在spfile中,只能通過Oracle語句更改)。
使用本庫作為恢復目錄
1.創建恢復目錄表空間
SQL> create tablespace tbs_rman datafile '/opt/oracle/oradata/orcl/tbs_rman01.dbf' size 200M autoextend on;
Tablespace created.
2.創建rman用戶並授權
SQL> create user rman identified by rman temporary tablespace temp default tablespace tbs_rman quota unlimited on tbs_rman;
User created.
SQL> grantrecovery_catalog_ownerto rman;
Grant succeeded.
測試
SQL> conn rman/rman
Connected.
SQL> select * from session_privs;
PRIVILEGE
----------------------------------------
CREATE SESSION
ALTER SESSION
CREATE TABLE
CREATE CLUSTER
CREATE SYNONYM
CREATE VIEW
CREATE SEQUENCE
CREATE DATABASE LINK
CREATE PROCEDURE
CREATE TRIGGER
CREATE TYPE
11 rows selected.
SQL> select * from session_roles;
ROLE
------------------------------
RECOVERY_CATALOG_OWNER
SQL>
3.連接恢復目錄並創建恢復目錄
[oracle@hxy ~]$ rlwrap rman catalog rman/rman@orcl //此處我連接的是我現有的當前數據庫
Recovery Manager: Release 10.2.0.1.0 - Production on Sat Feb 23 23:19:19 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to recovery catalog database
RMAN> create catalog tablespace tbs_rman;
recovery catalog created
4.連接到目標數據庫及恢復目錄
[oracle@hxy ~]$ rlwrap rman target / catalog rman/rman@orcl
Recovery Manager: Release 10.2.0.1.0 - Production on Sat Feb 23 23:29:03 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1334298584)
connected to recovery catalog database
RMAN> register database; --將目標數據庫注冊到恢復目錄
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
完成!!
使用自己新建的庫
自己在主機上新建一個數據庫,實例名為rman_db
確保能通過@連接
[oracle@hxy dbs]$ rlwrap sqlplus sys/oracle@rman_db as sysdb
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Feb 25 13:00:34 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
rmandb OPEN
[oracle@hxy dbs]$ rlwrap sqlplus sys/oracle@orcl as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Feb 25 12:59:52 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
orcl OPEN
(一下參考自 一沙彌的世界 博文)
1.在存儲恢復目錄的數據庫創建表空間用於存儲恢復目錄schema及恢復目錄數據(本文使用已經創建好的數據庫catadb來存儲恢復目錄)
[oracle@hxy ~]$ rlwrap sqlplus sys/oracle@rman_db as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Feb 25 13:06:52 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/rman_db/system01.dbf
/opt/oracle/oradata/rman_db/undotbs01.dbf
/opt/oracle/oradata/rman_db/sysaux01.dbf
/opt/oracle/oradata/rman_db/users01.dbf
SQL> create tablespace tbs_rman datafile '/opt/oracle/oradata/rman_db/tbs_rman01.dbf' size 20M autoextend on;
Tablespace created.
SQL>
2.創建rman用戶並授權
SQL> create user rman identified by rman temporary tablespace temp default tablespace tbs_rman quota unlimited on tbs_rman;
User created.
SQL> grant recovery_catalog_owner to rman;
Grant succeeded.
3.連接到恢復目錄並創建恢復目錄
[oracle@hxy ~]$rlwrap rman catalog rman/rman@rman_db
Recovery Manager: Release 10.2.0.1.0 - Production on Mon Feb 25 13:27:44 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to recovery catalog database
RMAN> create catalog tablespace tbs_rman;
recovery catalog created
RMAN>
4.連接到目標數據庫和恢復目錄,並將目標數據庫注冊到恢復目錄
[oracle@hxy ~]$rlwrap rman target sys/oracle@orcl catalog rman/rman@rman_db
Recovery Manager: Release 10.2.0.1.0 - Production on Mon Feb 25 13:31:20 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected totarget database: ORCL (DBID=1334298584)
connected torecovery catalog database
RMAN> register database;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
RMAN>
完成!!!
刪除
SQL> drop user rman cascade;
User dropped.
RMAN> drop catalog;
recovery catalog owner is
enter DROP CATALOG command again to confirm catalog removal
SQL> drop tablespace tbs_rman including contents and datafiles;
Tablespace dropped.
基於catalog的RMAN備份與恢復