#!/bin/bash
# 获取日期
#$(date +%Y%m%d)
# mkdir -p $(date +%Y%m%d)/log
# 定义局部变量
target_dir=/home/oracle/$(date +%Y%m%d)
#判断目录是否存在
if [[ ! -e "$target_dir" ]]
then
mkdir -p $target_dir
touch $target_dir/log
chown -R oracle:oinstall $target_dir
chmod -R 775 $target_dir
fi
su - oracle 1> $target_dir/log 2>&1 <<EOF
rman target /
run{
allocate channel c1 type disk maxpiecesize 500M;
allocate channel c2 type disk maxpiecesize 500M;
allocate channel c3 type disk maxpiecesize 500M;
crosscheck backup;
DELETE NOPROMPT EXPIRED BACKUPSET;
sql 'alter system archive log current';
BACKUP AS COMPRESSED BACKUPSET SKIP INACCESSIBLE TAG hot_db_bk_level0 FORMAT '$target_dir/bk_%s_%p_%t' FULL DATABASE;
sql 'alter system archive log current';
sql 'alter system archive log current';
sql 'alter system archive log current';
backup archivelog all format '$target_dir/arc_%t_%s';
backup current controlfile format '$target_dir/cntrl_%s_%p_%s';
crosscheck archivelog all;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
release channel c1;
release channel c2;
release channel c3;
}
EOF