1.创建RMAN 用的catalog 表空间
create tablespace RMAN datafile='/oracle/oradata/rman.dbf' size=200M reuse autoextend off extend management local autoallocate segment space management auto;
2. 创建RMAN用户:
> create user rman identified by rman default tablespace RMAN temporary tablespace temp quota unlimited on rman ;
3.授权:
>grant connect,resource to rman;
>grant recovery_catalog_owner to rman;
4.创建catalog
(1) C:\>rman catalog backup/oracle
恢复管理器: 版本9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
连接到恢复目录数据库
未安装恢复目录
RMAN> create catalog tablespace 'RMAN';
恢复目录已创建
RMAN>
(2) 到目标机器上。
$ rman catalog
backup/oracle@ocp target /
连接到恢复目录数据库
连接到目标数据库
>register database;
5. 注册完成以后可以看到相关的内容:
6.给crontrol 文件创建快照:
rman> set snapshot controlfile name to '/oracle/oradata/control.ctl';
rman> resync catalog;
1.创建RMAN 用的catalog 表空间
create tablespace RMAN datafile='/oracle/oradata/rman.dbf' size=200M reuse autoextend off extend management local autoallocate segment space management auto;
;
2. 创建RMAN用户:
> create user rman identified by rman default tablespace RMAN temporary tablespace temp quota unlimited on rman ;
3.授权:
>grant connect,resource to rman;
>grant recovery_catalog_owner to rman;
4.创建catalog
(1) C:\>rman catalog backup/oracle
恢复管理器: 版本9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
连接到恢复目录数据库
未安装恢复目录
RMAN> create catalog tablespace 'RMAN';
恢复目录已创建
RMAN>
(2) 到目标机器上。
$ rman catalog
backup/oracle@ocp target /
连接到恢复目录数据库
连接到目标数据库
>register database;
5. 注册完成以后可以看到相关的内容:
6.给crontrol 文件创建快照:
rman> set snapshot controlfile name to '/oracle/oradata/control.ctl';
rman> resync catalog;
7.进行资源备份需要修改的参数:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CO***OLFILE AUTOBACKUP ON;
CONFIGURE CO***OLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backup/%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 2;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL 1 DEVICE TYPE DISK MAXPIECESIZE 1000 M FORMAT '/backup/%d_%t_%U' CONNECT
'rman/rman@WHDX1';
CONFIGURE CHANNEL 2 DEVICE TYPE DISK MAXPIECESIZE 1000 M FORMAT '/backup/%d_%t_%U' CONNECT
'rman/rman@WHDX2';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE SNAPSHOT CO***OLFILE NAME TO '/backup/snapcf_WHDX1.f';
$rman catalog
rman/rman@tech
>connect target
sys/oracle@rac1
>configure channel device type disk format '/db01/backup/%U'
> configure retention policy to recovery window of 7 days
>查看当前的configure :
> show all
8. rman 中的一些命令:
> list backupset
>report schema
>list database
>show channel
>show device type
>show default device type;
>show retention poliyc
>show datafile backup copies;
>show maxsetsize;
>show exclude;
>show backup optimization;
运行一个文件:
>@full.sql
LIST INCARNATION OF DATABASE.
RMAN>resync catalog;
运行一个命令:
> sql "alter system switch logfile;"
运行一个操作系统命令:
> host "ls"
注消REGERISTER ORACLE:
% sqlplus
rman/cat@catdb
SQL> SELECT DB_KEY, DB_ID FROM DB WHERE DB_ID = 1237603294;
SQL> EXECUTE dbms_rcvcat.unregisterdatabase(db_key, db_id)
SELECT DBID FROM V$DATABASE;
DBID
---------
598368217
9. 在目标机器上(要被备份的机器上)运行如下的命令:
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
连接到目标数据库: OCP (DBID=2397384635)
连接到恢复目录数据库
10: 存储script 文件,并运行:
RMAN> replace script full_back{
2> allocate channel d1 type disk;
3> backup full format
4> '/d0102/backup/rman_%d_%U.bus' database;
5> }
运行它:
rman>run {execute script full_back;}
查看内容:
rman>print script full_back;
删除它:
rman>delete script full_back;
10 关于备份的机制:
(1) 脱机全备份脚本(full database offline backup:
for oracle 9i
#!/bin/ksh
rman target / <<EOF
shutdown immediate;
startup mount;
backup database format
'/d99/rmanback/brdstn/rman_%d_%t_%U.bus';
alter database open;
EOF
exit
for oracle 8i
#!/bin/ksh
rman target / nocatalog <<EOF
shutdown immediate;
startup mount;
run {
allocate channel d1 type disk;
backup database format
'/d99/rmanback/brdstn/rman_%d_%t_%U.bus';
}
alter database open;
EOF
Exit
(2) full database online backup
for oracle 9i
rman>backup database format
2> '/d99/rmanback/brdstn/rman_%d_%t_%U.bus';
for oracle 8i:
RMAN> run {
2> allocate channel d1 type disk;
3> backup database format
4> '/d99/rmanback/brdstn/rman_%d_%t_%U.bus';
5> }
(3) 备份一个表空间(tablespace)
oracle9i 的方法:
rman>backup tablespace system, users format
2> '/d99/rmanback/brdstn/rman_bckup_%d_%t_%U.bus';
oracle8i 的方法:
RMAN> run {
2> allocate channel d1 type disk;
3> backup format
4> '/d99/rmanback/brdstn/rman_bckup_%d_%t_%U.bus'
5> tablespace system, users include current controlfile;
6> }
(4) 备份数据文件(backing up datafile)
oracle 9i 的方法
RMAN> backup datafile 1,2;
如果指定的数据文件:
RMAN> run {
2> allocate channel d1 type disk;
3> backup format
4> '/d99/rmanback/brdstn/rman_bckup_%d_%t_%U.bus'
5> '/d01/oradata/workprd/users_01.dbf';
6> }
oracle 8i 的方法:
RMAN> run {
2> allocate channel d1 type disk;
3> backup format
4> '/d99/rmanback/brdstn/rman_bckup_%d_%t_%U.bus'
5> datafile 1, 2;
6> }
(5) 备份控制文件
oracle 9i中:
rman>configure controlfile autobackup on;
如果一定进行备份:
rman>backup current controlfile;
oracle8i 中一个备份当前controlfile script:
#!/bin/ksh
# File: backup_ctrl.ksh
#----------------------------------------------
export ORACLE_HOME=/d00/app/oracle/product/9.0.0
export ORACLE_SID=brdstn
export PATH=/usr/sbin:/usr/bin:$ORACLE_HOME/bin
export MAILX="/usr/ucb/Mail"
export MAIL_LIST="
chaya@garam.com"
#----------------------------------------------
BOX=`uname -a | awk '{print$2}'`
#----------------------------------------------
date
#----------------------------------------------
rman nocatalog log=rman_control.log <<EOF
connect target /
run {
allocate channel d1 type disk;
setlimit channel d1 kbytes 1900000;
backup
format '/d99/rmanback/brdstn/rman_cntl_%d_%t_%U.bct'
(current controlfile);
release channel d1;
}
EOF
#
if [ $? -ne 0 ]; then
$MAILX -s "RMAN problem with $ORACLE_SID on $BOX" \
$MAIL_LIST <<EOF
Check control file RMAN backups...
EOF
#
else
print "RMAN controlfile backup ran okay..."
fi
#----------------------------------------------
date
#----------------------------------------------
(6) 备份archivelog 文件
oracle 9i
RMAN> backup archivelog all;
备份时产生两个文件片
RMAN> backup database format
2> '/d00/backup/rman_%U.bus' plus archivelog;
oracle 9i,8i 中将它备份到磁带库中去的过程:
RMAN> run {
2> allocate channel t1 type 'sbt_tape';
3> backup filesperset 5 format
4> '/d0100/backup/ar_%d_%t.bus' (archivelog all );
5> }
每三天进行一次备份archivelog 文件:
#!/bin/ksh
# File: backup_arch.ksh
#----------------------------------------------
export ORACLE_HOME=/d00/app/oracle/product/9.0.0
export ORACLE_SID=brdstn
export PATH=/usr/sbin:/usr/bin:$ORACLE_HOME/bin
export MAILX="/usr/ucb/Mail"
export MAIL_LIST="
heeraa@chamak.com"
#----------------------------------------------
BOX=`uname -a | awk '{print$2}'`
#----------------------------------------------
date
#----------------------------------------------
rman nocatalog log=rman_arch_back.log <<EOF
connect target sys/pwd
run {
allocate channel d1 type disk;
setlimit channel d1 kbytes 1900000;
backup
format '/d99/backup/brdstn/arch_%d_%t.bus'
filesperset=50
archivelog from time 'sysdate-3';
release channel d1;
}
EOF
#
if [ $? -ne 0 ]; then
$MAILX -s "RMAN problem with $ORACLE_SID on $BOX" \
$MAIL_LIST <<EOF
Check archived redo RMAN backups...
EOF
#
else
print "RMAN archive backups ran okay..."
fi
#----------------------------------------------
date
#----------------------------------------------
(7)增量备份功能(incremental backups)
oracle 提供0-4级的增量备份
rman> backup incremental level 4 cumulative database
2> skip readonly;
12: 数据库(ARCHIVE 目录改变以后,如何进行处理
如果以前进行RMAN的备份,这个时侯出来,日志进行DEL后,进行RMAN备份时,会报错,因找不到原来的文件.
只能进行:
rman> CROSSCHECK ARCHIVELOG ALL;
然后再进行处理.