1. 创建基本目录
$ mkdir rmanbackup
然后在rmanbackup下面创建以下目录
$ mkdir scripts
$ mkdir archivelog
$ mkdir control
$ mkdir databak
$ mkdir log
2.创建脚本
$ vi rman_bak.sh
脚本内容:
#### script start ####
#!/bin/bash
#set env
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/11.2.0/
export ORACLE_SID=orcl
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export PATH=$ORACLE_HOME/bin:$PATH
DATE=`date +%w`
DATE_2=`date +%Y%m%d`
BACKUP_PATH=/u01/rmanbackup
TARGET_SID=orcl
BIN=$ORACLE_HOME/bin
echo "-----------------------------start-----------------------------";date
$BIN/rman log $BACKUP_PATH/log/$TARGET_SID.$DATE_2.log <
connect target /;
crosscheck archivelog all;
crosscheck backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
delete expired copy;
delete noprompt expired backup;
run{
allocate channel c1 type disk ;
backup as compressed backupset database format '$BACKUP_PATH/databak/full_%d_%T_%t_%s' tag='full';
backup as compressed backupset archivelog all delete all input skip inaccessible format '$BACKUP_PATH/archivelog/arch_%d_%t';
backup current controlfile format '$BACKUP_PATH/control/control_%d_%t';
release channel c1 ;
}
EOF
echo "------------------------------end------------------------------";date
#### script start ####
3.赋执行权限
$ chmod +x rman_bak.sh
4.做数据库全备
$ ./ rman_bak.sh
5.增加计划任务
$crontab -e
00 01 * * * . /opt/app/oracle/rman_bak/scripts/rman_bak.sh