通过Rman catalog 创建及管理Oracle数据库备份

基本环境信息
target DB (需备份数据库)
192.168.199.67 ORACLE_SID=zgw HOSTNAME=Oracle11 catlog DB (备份管理数据库) 192.168.199.68 ORACLE_SID=rman HOSTNAME=Oracle11_2 创建rman账号及相关设置 sqlplus / as sysdba select file_name, tablespace_name from dba_data_files group by tablespace_name; create tablespace catalog_tb datafile '/opt/oracle/oradata/rman/catalog_tb01.dbf' size 50M; create user rman identified by rman default tablespace catalog_tb; grant recovery_catalog_owner to rman; alter user rman quota unlimited on catalog_tb; grant dba to rman; grant connect,resource to rman; 配置catalog服务器tnsname.org文件 vi $ORACLE_HOME/network/admin/tnsnames.ora RMAN = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = rman) ) ) ZGW = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.199.67)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = zgw) ) ) 连接rman并创建catalog信息及注册数据库 rman catalog rman/rman target sys/oracle@zgw RMAN> create catalog; recovery catalog created ======================== SQL> show user USER is "RMAN" SQL> select count(*) from tab; COUNT(*) ---------- 142 ========================= RMAN> register database; database registered in recovery catalog starting full resync of recovery catalog full resync complete 查看target数据库的信息 RMAN> list incarnation; List of Database Incarnations DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time ------- ------- -------- ---------------- --- ---------- ---------- 2 19 ZGW 4066279841 PARENT 1 15-AUG-09 2 4 ZGW 4066279841 CURRENT 945184 18-MAY-15 RMAN> report schema; Report of database schema for database with db_unique_name ZGW List of Permanent Datafiles =========================== File Size(MB) Tablespace RB segs Datafile Name ---- -------- -------------------- ------- ------------------------ 1 680 SYSTEM YES /opt/oracle/oradata/zgw/system01.dbf 2 530 SYSAUX NO /opt/oracle/oradata/zgw/sysaux01.dbf 3 90 UNDOTBS1 YES /opt/oracle/oradata/zgw/undotbs01.dbf 4 5 USERS NO /opt/oracle/oradata/zgw/users01.dbf List of Temporary Files ======================= File Size(MB) Tablespace Maxsize(MB) Tempfile Name ---- -------- -------------------- ----------- -------------------- 1 29 TEMP 32767 /opt/oracle/oradata/zgw/temp01.dbf
备份脚本
[oracle@Oracle11_2 scripts]$ cat rman_backup.sh #!/bin/bash #this is rman catalog auto full backup script #date 2015-06-02
#环境变量 NLS_LANG
=AMERICAN_AMERICA.AL32UTF8 ORACLE_SID=rman ORACLE_BASE=/opt/oracle ORACLE_HOME=/opt/oracle/11g PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin BAK_HOME=/backup export ORACLE_SID ORACLE_BASE ORACLE_HOME NLS_LANG PATH
#时间戳 backtime
=`date +"20%y%m%d%H%M%S"`
#执行远程创建目录命令
ssh -l oracle Oracle11 "mkdir -p $BAK_HOME/$backtime" cd $ORACLE_HOME/bin rman catalog rman/rman target sys/oracle@zgw log=$BAK_HOME/$backtime/backupall_$backtime.log <<EOF run{ allocate channel c1 device type disk; allocate channel c2 device type disk; crosscheck backup; sql 'alter system archive log current'; backup database format '$BAK_HOME/$backtime/%d_%T_%U'; backup current controlfile format '$BAK_HOME/$backtime/%d_cntrl_%s_%p_%s'; backup spfile format '$BAK_HOME/$backtime/%d_spfile_%U.bak'; backup archivelog all format '$BAK_HOME/$backtime/%d_arc_%t_%s' delete all input; crosscheck archivelog all; delete noprompt expired backup; delete noprompt obsolete; delete noprompt backup of database completed before 'sysdate - 30'; release channel c1; release channel c2; } EOF echo "backup complete!"
此脚本功能:
1.备份数据文件
2.备份spfile
3.备份控制文件
4.备份archivelog
5.清除已备份的archivelog文件
6.清除30天以前的备份记录

注意:
1.备份日志会写入rman本机的$BAK_HOME/$backtime/backupall_$backtime.log目录中。
2.备份数据写入target数据库服务器的$BAK_HOME/$backtime 目录中。
3.此脚本在rman服务器上执行。

参考:http://www.cnblogs.com/gaojian/p/3604814.html

http://blog.csdn.net/staricqxyz/article/details/8306447

posted @ 2015-06-02 18:23  艾阳君  阅读(440)  评论(0编辑  收藏  举报