创建恢复目录

在hndx上创建恢复目录:
[oracle@oracle admin]$ export ORACLE_SID=hndx
[oracle@oracle admin]$ sqlplus / as sysdba

SQL> create tablespace rman_cata datafile '/u01/app/oracle/oradata/hndx/cata01.dbf' size 10M;
SQL> create user rman_cata default tablespace rman_cata identified by oracle;

SQL> grant connect,resource,recovery_catalog_owner to rman_cata;
SQL> exit

[oracle@oracle admin]$ echo $ORACLE_SID
hndx

sqlplus rman_cata/oracle
select * from tab--没有对象

[oracle@oracle admin]$ rman catalog rman_cata/oracle
RMAN> create catalog;

sqlplus rman_cata/oracle
select * from tab;--发现有上100个对象

[oracle@oracle admin]$ rman target sys/oracle@orcl catalog rman_cata/oracle@hndx
RMAN> register database;--将目标数据库的信息注册到恢复目录数据库

手动添加备份元数据

SQL> alter tablespace users begin backup;
SQL> !cp -v /u01/app/oracle/oradata/orcl/users01.dbf /u01/backup/hotbk/users.bak
SQL> alter tablespace users end backup;

RMAN> catalog datafilecopy '/u01/backup/hotbk/users.bak' ;
RMAN> list copy of tablespace users;

RMAN> change datafilecopy '/u01/backup/hotbk/users01.dbf' uncatalog;--从控制文件的元数据中删除此项
RMAN> list copy of tablespace users;

RMAN> catalog datafilecopy '/u01/backup/hotbk/users01.dbf' tag=users;--注册的同时进行标记

VPC(Virtual Private Catalog)

假如有3个数据库,数据名分别为:orcl,orcl1,orcl2,创建一个catalog服务器orcl,同时为2台数据库提供服务
要求每个数据库dba只能看到自己的元数据

首先,需要创建一个包含所有目标数据库的基础目录,假设拥有者为:RMAN

1. 创建表空间:
create tablespace rman_tbs datafile '/u01/app/oracle/oradata/orcl/rman_tbs01.dbf' size 100M;

2. 创建RMAN用户:
create user rman default tablespace rman_tbs identified by oracle;
grant recovery_catalog_owner to rman;

3. 创建恢复目录:
rman catalog rman/oracle
create catalog;

4. 将orcl1和orcl2的信息注册到恢复目录:
export ORACLE_SID=orcl1
rman target / catalog rman/oracle@orcl
register database;

export ORACLE_SID=orcl2
rman target / catalog rman/oracle@orcl
register database;

现在无无论orcl1和orcl2的dba都能考到对方的数据,这是不安全的,如:
export ORACLE_SID=orcl1
rman target / catalog rman/oracle@orcl
list db_unique_name all;

为了安全,不让对方dba看到自己的数据,可以创建虚拟专用目录,如:

1. 创建虚拟专用目录的所有者:
create user orcl1 default tablespace users identified by oracle;
create user orcl2 default tablespace users identified by oracle;

2. 为虚拟专用目录的所有者受权:
export ORACLE_SID=orcl

sqlplus / as sysdba
grant recovery_catalog_owner to orcl1;
grant recovery_catalog_owner to orcl2;

rman catalog rman/oracle
grant catalog for database orcl1 to orcl1;
grant register database to orcl1;

grant catalog for database orcl2 to orcl2;
grant register database to orcl2;

3. 创建虚拟专用目录:
export ORACLE_SID=orcl1

rman target / catalog orcl1/a@orcl
create virtual catalog;
list db_unique_name all;
只能看到自己的数据

export ORACLE_SID=orcl2
rman target / catalog orcl2@orcl
create virtual catalog;
list db_unique_name all;
只能看到自己的数据

合并恢复目录

1. 删除以上实验的恢复目录,在orcl和orcl1上重新创建各自的catalog

export ORACLE_SID=orcl1
rman target / catalog orcl1/oracle@orcl
unregister database;

export ORACLE_SID=orcl2
rman target / catalog orcl2/oracle@orcl
unregister database;

export ORACLE_SID=orcl
rman target / catalog rman/oracle
drop catalog;

2. 重新创建catalog:

export ORACLE_SID=orcl
rman catalog rman/oracle
create catalog;
connect target /
register database;
list db_unique_name all;

3. 为orcl1创建自己的catalog:

export ORACLE_SID=orcl1
sqlplus / as sysdba
create user rman1 default tablespace users identified by oracle;
grant connect,resource,recovery_catalog_owner to rman1;

rman catalog rman1/oracle
create catalog;
connect target /
register database;
list db_unique_name all;

4. 将orcl1的恢复目录合并到orcl中:

export ORACLE_SID=orcl
rman target / catalog rman/oracle
import catalog rman1/oracle@orcl1;

list db_unique_name all;
发现orcl1已经合并到orcl中

export ORACLE_SID=orcl1
rman target / catalog rman1/oracle
list db_unique_name all;
发现为空

-------------------------------------------------------------------------

恢复目录
createa tablespace cata_tbs datafile '/u01/app/oracle/oradata/orcl/cata_tbs01.dbf' size 100M; -- no less than 15M

create user cata default tablespace cata_tbs identified by oracle;
grant connect,resource,recovery_catalog_owner to cata;

sqlplus cata/oracle
select * from tab;

rman catalog cata/oracle;
create catalog;

rman target / catalog cata/oracle;
register database;

backup database;

怎么在恢复目录中注册数据库
rman target sys/oracle@orcl1 catalog cata/oracle@orcl
register database;
unregister database;

注册额外的备份文件
rman> catalog backuppiece 'file_name';

alter tablespace users begin backup;
!cp -v /u01/app/oracle/oradata/orcl/users01.dbf /u01/app/oracle/backup/hotbk
alter tablespace users end backup;

catalog datafilecopy '/u01/app/oracle/backup/hotbk';

list copy of database;

重新同步控制文件和恢复目录
rman>resync catalog;

使用rman存储脚本
CREATE [GLOBAL] SCRIPT script_name FROM FILE 'file_name';
rman target / catalog cata/oracle;
create script backupdb {backup database format='/u01/app/oracle/imanbk/%d_%s.dbf';}

run{execute script
script name;
}

RUN { EXECUTE GLOBAL SCRIPT
script_name
; }

print script scriptname;
print script backdb to file '/u01/app/oracle/rmanbk.sh';

rman> list script names;
rman> replace script backdb
{delete noprompt backup;
backup database plus archivelog;
}

list script names;
print script backdb;

posted on 2013-10-22 16:00  逝者如斯(乎)  阅读(323)  评论(0编辑  收藏  举报