生产环境rman备份脚本

概述 

RMAN(Recovery Manager)是Oracle数据库的备份和恢复工具。它是Oracle提供的官方工具,专门用于管理数据库备份、还原和恢复操作。

内容

#!/bin/bash
#source /home/orace/.bash_profile
export ORACLE_SID=oa2
export DATE=`date +%F`
export BACK_DIR='/u01/oa_backup/'
mkdir -p $BACK_DIR/$DATE
rman log=$BACK_DIR/$DATE/rman_backup_$DATE.log target / <<EOF
run{
   CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 3 DAYS;
   CONFIGURE CONTROLFILE AUTOBACKUP ON;
   CONFIGURE CONTROLFILE autobackup format for device type disk to '$BACK_DIR/$DATE/CONTROLFILE.%F';
   ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT '$BACK_DIR/$DATE/full_%d_%T_%s.bak';
   ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT '$BACK_DIR/$DATE/full_%d_%T_%s.bak';
   ALLOCATE CHANNEL disk3 DEVICE TYPE DISK FORMAT '$BACK_DIR/$DATE/full_%d_%T_%s.bak';
   SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
   BACKUP as compressed  backupset  DATABASE  SKIP INACCESSIBLE FILESPERSET 10 PLUS ARCHIVELOG FILESPERSET 20 DELETE ALL INPUT;
   SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
   CROSSCHECK BACKUP;
   CROSSCHECK ARCHIVELOG ALL;
   DELETE NOPROMPT EXPIRED BACKUP;
   DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
   DELETE NOPROMPT OBSOLETE;
   RELEASE channel disk1;
   RELEASE channel disk2;
   RELEASE channel disk3;
}
EOF

export EXPIRE_DATE=`date +%F -d '+3 day ago'`
rm -rf $BACK_DIR/$EXPIRE_DATE
exit

 

posted @ 2023-10-22 11:36  雪竹子  阅读(115)  评论(0编辑  收藏  举报