vim level0_backup.sh
- #!/bin/bash
-
- # .bash_profile
-
- # Get the aliases and functions
- if [ -f ~/.bashrc ]; then
- . ~/.bashrc
- fi
-
- # User specific environment and startup programs
-
- PATH=$PATH:$HOME/bin
-
- export PATH
-
- export ORACLE_SID=orcl
- export ORACLE_BASE=/u01/app/oracle
- export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
- export PATH=$PATH:$ORACLE_HOME/bin
-
- dateTime=`date +%Y-%m-%d`
-
- rman cmdfile=/u01/app/ora_backup/backup_scripts/level0_backup.rcv msglog=/u01/app/ora_backup/backup_logs/level0_${dateTime}.log
-
-
vim level0_backup.rcv
- connect target sys/***@orcl
- run{
- crosscheck backup;
-
- crosscheck archivelog all;
-
- delete noprompt obsolete;
-
- delete noprompt expired backup;
- allocate channel d1 type disk;
- allocate channel d2 type disk;
- backup incremental level 0 as compressed backupset database format '/dbbak/backup/LEVEL0/level0_%d_%s_%p_%u.bak'
- tag='level 0' include current controlfile;
- sql'alter system archive log current';
- backup as compressed backupset archivelog all format '/dbbak/backup/LEVEL0/log_%d_%s_%p_%u.bak' delete all input;
- backup spfile tag='spfile' format='/dbbak/backup/LEVEL0/spfile_%U_%T';
- delete force noprompt archivelog all completed before 'sysdate-7';
- release channel d2;
- release channel d1;
- }
vim level1_backup.sh
- #!/bin/bash
-
- # .bash_profile
-
- # Get the aliases and functions
- if [ -f ~/.bashrc ]; then
- . ~/.bashrc
- fi
-
- # User specific environment and startup programs
-
- PATH=$PATH:$HOME/bin
-
- export PATH
-
- export ORACLE_SID=orcl
- export ORACLE_BASE=/u01/app/oracle
- export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
- export PATH=$PATH:$ORACLE_HOME/bin
-
- dateTime=`date +%Y-%m-%d`
-
- rman cmdfile=/u01/app/ora_backup/backup_scripts/level1_backup.rcv msglog=/u01/app/ora_backup/backup_logs/level1_${dateTime}.log
vim level1_backup.rcv
- connect target sys/***@orcl
- run{
- crosscheck backup;
-
- crosscheck archivelog all;
-
- delete noprompt obsolete;
-
- delete noprompt expired backup;
- allocate channel d1 type disk;
- backup incremental level 1 as compressed backupset database format '/ora_backup/backup_sets/LEVEL1/level1_%d_%s_%p_%u.bak'
- tag='level 1';
- sql'alter system archive log current';
- backup as compressed backupset archivelog all format '/ora_backup/backup_sets/LEVEL1/log_%d_%s_%p_%u.bak' delete all input;
- delete force noprompt archivelog all completed before 'sysdate-7';
- release channel d1;
- }
vim level2_backup.sh
- #!/bin/bash
-
- # .bash_profile
-
- # Get the aliases and functions
- if [ -f ~/.bashrc ]; then
- . ~/.bashrc
- fi
-
- # User specific environment and startup programs
-
- PATH=$PATH:$HOME/bin
-
- export PATH
-
- export ORACLE_SID=orcl
- export ORACLE_BASE=/u01/app/oracle
- export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
- export PATH=$PATH:$ORACLE_HOME/bin
-
- dateTime=`date +%Y-%m-%d`
-
- rman cmdfile=/u01/app/ora_backup/backup_scripts/level2_backup.rcv msglog=/u01/app/ora_backup/backup_logs/level2_${dateTime}.log
vim level2_backup.rcv
- connect target sys/***@orcl
- run{
- crosscheck backup;
-
- crosscheck archivelog all;
-
- delete noprompt obsolete;
-
- delete noprompt expired backup;
- allocate channel d1 type disk;
- backup incremental level 2 as compressed backupset database format '/ora_backup/backup_sets/LEVEL2/level2_%d_%s_%p_%u.bak'
- tag='level 2';
- sql'alter system archive log current';
- backup as compressed backupset archivelog all format '/ora_backup/backup_sets/LEVEL2/log_%d_%s_%p_%u.bak' delete all input;
- delete force noprompt archivelog all completed before 'sysdate-7';
- release channel d1;
- }
vim level0_backup_arch.sh
- #!/bin/bash
-
- # .bash_profile
-
- # Get the aliases and functions
- if [ -f ~/.bashrc ]; then
- . ~/.bashrc
- fi
-
- # User specific environment and startup programs
-
- PATH=$PATH:$HOME/bin
-
- export PATH
-
- export ORACLE_SID=orcl
- export ORACLE_BASE=/u01/app/oracle
- export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
- export PATH=$PATH:$ORACLE_HOME/bin
-
- dateTime=`date +%Y-%m-%d`
-
- rm -f /ora_archive_bk/arch/LEVEL0/*
-
- rman cmdfile=/u01/app/ora_backup/backup_scripts/level0_backup_arch.rcv msglog=/u01/app/ora_backup/backup_logs/level0_arch_${dateTime}.log
vim level0_backup_arch.rcv
- connect target sys/***@orcl
- run{
- crosscheck backup;
-
- crosscheck archivelog all;
-
- delete noprompt obsolete;
-
- delete noprompt expired backup;
- allocate channel d1 type disk;
- allocate channel d2 type disk;
- backup incremental level 0 as compressed backupset database format '/dbbak/LEVEL0/level0_%d_%s_%p_%u.bak'
- tag='level 0' include current controlfile;
- sql'alter system archive log current';
- backup as compressed backupset archivelog all format '/dbbak/LEVEL0/log_%d_%s_%p_%u.bak' delete all input;
- backup spfile tag='spfile' format='/dbbak/LEVEL0/spfile_%U_%T';
- delete force noprompt archivelog all completed before 'sysdate-7';
- release channel d2;
- release channel d1;
- }
<2>.备份归档文件
vim level0_bk_arch.sh
- #!/bin/bash
-
- # .bash_profile
-
- # Get the aliases and functions
- if [ -f ~/.bashrc ]; then
- . ~/.bashrc
- fi
-
- # User specific environment and startup programs
-
- PATH=$PATH:$HOME/bin
-
- export PATH
-
- export ORACLE_SID=orcl
- export ORACLE_BASE=/u01/app/oracle
- export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
- export PATH=$PATH:$ORACLE_HOME/bin
-
- dateTime=`date +%Y%m%d`
- cd /dbbak/arch_rar_file
-
- #加密打包拷贝
- /usr/local/bin/rar -p"****" a -agYYYYMMDD -ep -ta`date +%F` -r /dbbak/arch_rar_file/BkArc_ /dbbak/LEVEL0/*.* /u01/app/ora_backup/control_backup/*$dateTime*
crontab -l
- 0 5 1 * * sh /u01/app/ora_backup/backup_scripts/level0_bk_arch.sh
- 10 1 * * 0 sh /u01/app/ora_backup/backup_scripts/level0_backup.sh
- 10 1 1 * * sh /u01/app/ora_backup/backup_scripts/level0_backup_arch.sh
- 10 1 * * 3,6 sh /u01/app/ora_backup/backup_scripts/level1_backup.sh
- 10 1 * * 1,2,4,5 sh /u01/app/ora_backup/backup_scripts/level2_backup.sh
- #DG备库定时清理应用过的日志
- 10 1 * * * sh /home/oracle/clear_archlog.sh
vim clear_archlog.sh
- #!/bin/sh
-
- BACK_DIR=/home/oracle/clear_archlog
-
- export DATE=`date +%F`
-
- mkdir $BACK_DIR/$DATE
-
- echo " " >> $BACK_DIR/$DATE/rman_backup.log
-
- echo `date '+%Y-%m-%d %H:%M:%S'` >> $BACK_DIR/$DATE/rman_backup.log
-
- su - oracle -c "
- rman log=$BACK_DIR/$DATE/rman_backup.log target / <
- # delete force archivelog all completed before 'sysdate - 1'; # 这里执行清除归档日志,如果不想手动输入YES,则可以添加noprompt参数
- delete force noprompt archivelog all completed before 'sysdate - 2';
- exit;
- EOF
- "
-
- echo " " >> $BACK_DIR/$DATE/rman_backup.log