0级备份脚本(bak_lv_0)
#!/bin/bash
export PATH
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=dbserver.localdomain
export ORACLE_SID=datacenter
export ORACLE_BASE=/arcerzhangoracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_UNQNAME=datacenter
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORACLE_TERM=xterm
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export EDITOR=vi
export LANG=en_US
export NLS_LANG=american_america.AL32UTF8
export NLS_DATE_FORMAT='yyyy/mm/dd hh24:mi:ss'
/arcerzhangoracle/app/oracle/product/11.2.0/db_1/bin/rman <<EOF
connect target /
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level 0 database format '/arcerzhangoracle/Rmanbackup/level0_%d_%s_%p_%u_%T.bkp';
sql 'alter system archive log current';
backup archivelog all delete input format '/arcerzhangoracle/Rmanbackup/log_%d_%s_%p_%u_%T.bkp';
release channel c1;
release channel c2;
}
crosscheck backup;
delete noprompt obsolete;
exit;
EOF
1级备份脚本(bak_lv_1)
#!/bin/bash
export PATH
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=dbserver.localdomain
export ORACLE_SID=datacenter
export ORACLE_BASE=/arcerzhangoracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_UNQNAME=datacenter
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORACLE_TERM=xterm
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export EDITOR=vi
export LANG=en_US
export NLS_LANG=american_america.AL32UTF8
export NLS_DATE_FORMAT='yyyy/mm/dd hh24:mi:ss'
/arcerzhangoracle/app/oracle/product/11.2.0/db_1/bin/rman <<EOF
connect target /
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level 1 database format '/arcerzhangoracle/Rmanbackup/level1_%d_%s_%p_%u_%T.bkp';
sql 'alter system archive log current';
backup archivelog all delete input format '/arcerzhangoracle/Rmanbackup/log_%d_%s_%p_%u_%T.bkp';
release channel c1;
release channel c2;
}
crosscheck backup;
delete noprompt obsolete;
exit;
EOF
2级备份脚本(bak_lv_2)
#!/bin/bash
export PATH
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=dbserver.localdomain
export ORACLE_SID=datacenter
export ORACLE_BASE=/arcerzhangoracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_UNQNAME=datacenter
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORACLE_TERM=xterm
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export EDITOR=vi
export LANG=en_US
export NLS_LANG=american_america.AL32UTF8
export NLS_DATE_FORMAT='yyyy/mm/dd hh24:mi:ss'
/arcerzhangoracle/app/oracle/product/11.2.0/db_1/bin/rman <<EOF
connect target /
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level 2 database format '/arcerzhangoracle/Rmanbackup/level2_%d_%s_%p_%u_%T.bkp';
sql 'alter system archive log current';
backup archivelog all delete input format '/arcerzhangoracle/Rmanbackup/log_%d_%s_%p_%u_%T.bkp';
release channel c1;
release channel c2;
}
crosscheck backup;
delete noprompt obsolete;
exit;
EOF
crontab中的定时任务脚本参考
00 03 * * 0 /home/oracle/BackupScripts/bak_lv_0 >> /home/oracle/RmanBackup/bak_lv_0.log
00 03 * * 1,2,4,5,6 /home/oracle/BackupScripts/bak_lv_2 >> /home/oracle/RmanBackup/bak_lv_2.log
00 03 * * 3 /home/oracle/BackupScripts/bak_lv_1 >> /home/oracle/RmanBackup/bak_lv_1.log
00 01 * * * /arcerzhangoracle/auto_bak_exp/auto_bak_expdp.sh