1、创建rman数据库
(1)为目录创建一个单独的表空间
先创建一个back数据库
创建表空间
create tablespace back datafile 'filename' size 500m;
(2)创建rman用户
create user rman identified by rman default tablespace back temporary tablespace temp;
(3)该rman授予权限
grant connect,resource,recovery_catalog_owner to rman;
(4)创建恢复目录
$rman
connect catalog rman/rman
create catalog tablespace back;
(5)注册目标数据库
连接数据库
rman target system/system@db1 catalog rman/rman@catalog
修改tnsnames.ora文件增加SERVER=DEDICATED,修改后如下:
DB1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = yninfo_dafen)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER=DEDICATED)(SERVICE_NAME = db1)
)
)
注册数据库
register database;
2、注销数据库
(1)连接目标数据库,获取目标数据库ID
rman target system/system@db1 catalog rman/rman@catalog
得到rman(dbid=1231209694)的信息
(2)查询恢复目录
select db_key,db_id from db where db_id=1231209694;
(3)注销数据库
execute dbms_rcvcat.unregisterdatabase(1,1231209694)
3、备份/恢复
备份整个数据库
backup full tag 'basicdb' format '/bak/prod/full_%u_%s_%p' database;
备份一个表空间
backup tag 'tsuser' format '/bak/prod/tsuser_%u_%s_%p' tablespace users;
备份归档日志
backup tag 'alog' format '/bak/prod/archive/arcbk_%u_%s_%p' archivelog all delete input;
全库备份:
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup full tag 'basicdb' format '/bak/prod/full_%u_%s_%p' database;
include current controlfile;
sql 'alter system archive log current';
backup fileaperset 3 format '/bak/prod/arch_%u_%s_%p'
archivelog all delete input;
release channel c1;
release channel c2;
release channel c3;
}
全库恢复:
rman>
run {
allocate channel 'dev1' type disk ;
allocate channel 'dev2' type disk ;
allocate channel 'dev3' type disk ;
restore database ;
recover database ;
release channel dev1 ;
release channel dev2 ;
release channel dev3 ;
}
4、维护rman
1)查看rman信息
list backup;查看rman的信息
report obsolete;列出过期备份
删除过期备份
run{
alocate channel for maintenance type disk;
change backup id delete;
releace channel;
}
2)同步或重置rman
如果目标数据库物理对象发生了变化,如添加一个数据文件,需用如下命令同步:
resync catalog;
如果目标数据库reset了数据库,需用如下命令同步:
reset database;
当手工删除了数据库的归档文件后,需执行以下脚本同步:
run{
allocate channel for maintenance type disk;
change archivelog all crosscheck;
release chyannel;
}
当手工删除了数据库的rman备份后,需要执行以下脚本来同步:
run{
allocate channel fro maintenance type disk;
recosscheck backup;
delete expired backup;
release channel;
}
5、自动备份
1)生成备份脚本文件backup.rcv如下:
connect target system/system@db1
connect rcvcat rman/rman@back
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup full tag 'db1' format 'D:/oracle/backup/full_%u_%s_%p' database
include current controlfile;
sql 'alter system archive log current';
backup filesperset 3 format 'D:/oracle/backup/arch_%u_%s_%p'
archivelog all delete input;
release channel c1;
release channel c2;
release channel c3;
}
2)生成执行文件backup.bat(linux生成.sh文件)如下:
rman cmdfile=D:/oracle/backup/delete.rcv msglog=D:/oracle/backup/backup.txt
3)加入调度
at 23:00 /every:Su cmd/c "D:/oracle/backup/delete.bat"
表示星期天23点对数据库备份
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/flcandclf/archive/2007/05/30/1630448.aspx