Oracle用指令碼定時執行備份

zhenghaishu發表於2015-06-16


1 備份策略

    每週日做0級備份,每週一~週六做1級備份。


2 備份指令碼

1)0級備份指令碼

指令碼名稱:backup_ora_level0.sh

存放目錄:/home/oracle

指令碼內容:

#!/bin/bash


export PATH=$PATH:$ORACLE_HOME/bin

export TIME=`date +%Y%m%d%H%M`

rman TARGET / log /home/oracle/rmanlog/${TIME}.log<

RUN {

 CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;

 CONFIGURE CONTROLFILE AUTOBACKUP ON;

 CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/oracle10g/backup/%F';

 ALLOCATE CHANNEL C1 DEVICE TYPE DISK FORMAT '/home/oracle/oracle10g/backup/bak_level0_%T_%U';

 BACKUP INCREMENTAL LEVEL=0 DATABASE SKIP INACCESSIBLE PLUS ARCHIVELOG FILESPERSET 20 DELETE ALL INPUT;

 RELEASE CHANNEL C1;

 }

 ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;

 CROSSCHECK BACKUPSET;

 DELETE NOPROMPT OBSOLETE;


2)1級備份指令碼

指令碼名稱:backup_ora_level1.sh

存放目錄:/home/oracle

指令碼內容:

#!/bin/bash


export PATH=$PATH:$ORACLE_HOME/bin

export TIME=`date +%Y%m%d%H%M`

rman TARGET / log /home/oracle/rmanlog/${TIME}.log<

RUN {

 CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;

 CONFIGURE CONTROLFILE AUTOBACKUP ON;

 CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/oracle10g/backup/%F';

 ALLOCATE CHANNEL C1 DEVICE TYPE DISK FORMAT '/home/oracle/oracle10g/backup/bak_level1_%T_%U';

 BACKUP INCREMENTAL LEVEL=1 DATABASE SKIP INACCESSIBLE PLUS ARCHIVELOG FILESPERSET 20 DELETE ALL INPUT;

 RELEASE CHANNEL C1;

 }

 ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;

 CROSSCHECK BACKUPSET;

 DELETE NOPROMPT OBSOLETE;


3)定時執行指令碼

利用crontab在每週一二三四五六的凌晨一點執行1級備份,每週日的凌晨一點執行0級備份。具體命令為:

~> crontab -e

0 1 * * 0 /home/oracle/backup_ora_level0.sh

0 1 * * 1,2,3,4,5,6 /home/oracle/backup_ora_level1.sh

 


  DELETE ALL INPUTDELETE ALL INPUTDELETE ALL INPUT

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29485627/viewspace-1701351/,如需轉載,請註明出處,否則將追究法律責任。

相關文章