数据库版本:Oracle 10.2.0.5 x86_64
操作系统版本:Oracle Linux 5.7 x86_64
注:#表示为root用户下输入该命令, $表示为oracle用户下输入该命令。
1.创建rman catalog
# su - oracle
$ sqlplus / as sysdba
SQL>
create tablespace CATALOG
datafile '/u02/oradata/data/CATALOG_01.dbf'
size 20M
autoextend on
next 5M maxsize 2G
extent management local;
SQL>
create user rman identified by rman
default tablespace CATALOG
temporary tablespace TEMP_SPC
quota unlimited on CATALOG;
SQL> grant connect,recovery_catalog_owner to rman;
SQL> exit
$ rman target system/system123 catalog rman/rman
RMAN> create catalog;
RMAN> register database;
2.创建目录
$ mkdir -p /u01/oracle/backup/orcl 存放备份文件
$ mkdir -p /u01/oracle/backup/orcl/log 存放备份日志
$ mkdir -p /home/oracle/script 存放脚本
3.创建脚本
备份计划:每天凌晨一点进行数据库全备和归档日志备份。
$ cd /home/oracle/script
创建shell脚本db_backup_orcl.sh
创建rman脚本db_backup_orcl.rcv
(脚本内容在本文档最后面)
赋予两个脚本执行的权限:
$ chmod 775 db_backup_orcl.sh
$ chmod 775 db_backup_orcl.rcv
4.制定定时计划
每天凌晨1点运行备份脚本
# crontab -u oracle -e 添加以下内容:
- 01 1 * * * /home/oracle/script/db_backup_orcl.sh >/dev/null 2>&1
脚本:
db_backup_orcl.sh
- #!/bin/bash
- source /home/oracle/.bash_profile
- ORACLE_SID=orcl
- export ORACLE_SID
- #当天时间
- DATA=`date +"%Y-%m-%d"`
- #检查备份存放目录是否存在,没有的话就创建
- BK_PATH=/u01/oracle/backup/$ORACLE_SID
- if [ ! -d $BK_PATH ]; then
- mkdir -p $BK_PATH
- fi
- #检查备份日志存放目录是否存在,没有的话就创建
- LOG_PATH=/u01/oracle/backup/$ORACLE_SID/log
- if [ ! -d $LOG_PATH ]; then
- mkdir -p $LOG_PATH
- fi
- #检查备份日志文件是否存在,没有的话就创建
- LOG_FILE=$LOG_PATH/bk_$DATA.log
- if [ ! -f $LOG_FILE ]; then
- touch $LOG_PATH/bk_$DATA.log
- fi
- rman=/u01/oracle/10.2.0/bin/rman
- $rman cmdfile=/home/oracle/script/db_backup_orcl.rcv msglog=$LOG_FILE
db_backup_orcl.rcv
- connect catalog rman/rman
- connect target sys/sys123
- run {
- allocate channel d1 type disk;
- allocate channel d2 type disk;
- backup
- incremental level 0
- tag 'db_level_0'
- filesperset 20
- format '/u01/oracle/backup/orcl/df_%t_%s_%p'
- database;
- sql 'alter system archive log current';
- backup archivelog all delete input
- filesperset 20
- format '/u01/oracle/backup/orcl/al_%t_%s_%p';
- release channel d2;
- release channel d1;
- }
- crosscheck backup;
- resync catalog;