Oracle 集中備份指令碼

crazyboytan發表於2012-10-12

0級備份完整指令碼

#!/bin/bash

begintime=`date`

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1

export ORACLE_SID=caland

export BACKUP_DIR=/arch/backup/caland

export PATH=$PATH:$ORACLE_HOME/bin

rq=` date +"20%y"-"%m"-"%d"-"%H":"%M":"%S" `

/u01/app/oracle/product/10.2.0/db_1/bin/rman target sys/oracle@caland log=/backup_scripts/caland/log/backup_0_$rq.log<

run

{

CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '$BACKUP_DIR/$ORACLE_SID-%F.ctl';

CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COMPRESSED BACKUPSET;

CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT '$BACKUP_DIR/$ORACLE_SID-%U.bak';

backup incremental level=0 database format='$BACKUP_DIR/$ORACLE_SID-%U-$rq.bak' ;

sql 'alter system archive log current';

backup archivelog all not backed up 1 times format='$BACKUP_DIR/$ORACLE_SID-%U-$rq.arc';

delete noprompt obsolete;

delete archivelog all completed before 'sysdate-7';

}

LIST BACKUP;

EOF

endtime=`date`

echo "begin time:" $begintime

echo "end time:" $endtime

2級備份完整指令碼

#!/bin/bash

begintime=`date`

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1

export ORACLE_SID=caland

export BACKUP_DIR=/arch/backup/caland

export PATH=$PATH:$ORACLE_HOME/bin

rq=` date +"20%y"-"%m"-"%d"-"%H":"%M":"%S" `

/u01/app/oracle/product/10.2.0/db_1/bin/rman target sys/oracle@caland log=/backup_scripts/caland/log/backup_0_$rq.log<

run

{

CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '$BACKUP_DIR/$ORACLE_SID-%F.ctl';

CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COMPRESSED BACKUPSET;

CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT '$BACKUP_DIR/$ORACLE_SID-%U.bak';

backup incremental level=2 database format='$BACKUP_DIR/$ORACLE_SID-%U-$rq.bak' ;

sql 'alter system archive log current';

backup archivelog all not backed up 1 times format='$BACKUP_DIR/$ORACLE_SID-%U-$rq.arc';

delete noprompt obsolete;

delete archivelog all completed before 'sysdate-7';

}

LIST BACKUP;

EOF

endtime=`date`

echo "begin time:" $begintime

echo "end time:" $endtime

計劃任務

每週六做0級備份,其餘每天做2級備份

[oracle@rhel ~]$ crontab -e

0 4 * * 6 /backup_scripts/caland/backup_caland_level_0.sh >> /backup_scripts/caland/log/backup_caland_level_0.log 2>&1

0 4 * * 0,1,2,3,4,5 /backup_scripts/caland/backup_caland_level_2.sh>>/backup_scripts/caland/log/backup_caland_level_2.log 2>&1

域允許值範圍

分鐘 0-59

小時 0-23

1-31

1-12 (或者用jan/feb等名字)

星期幾 0-7 (07是週日,也可以用mon,tue等表示)

其他

備份和歸檔寫成一句

backup incremental level=2 database format='/arch/backup/caland/%U.bak' plus archivelog format='/arch/backup/caland/%U.arc' delete input;

[@more@]

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

相關文章