1, the database is fully prepared to the hard disk
[[Email protected] scripts]$ cat rman_backup.sh source /home/oracle/.bash_ profile rman target / log=/home/oracle/backup/backupall_rman.log<<eof run { allocate channel ch1 device type disk; # Allocation channel allocate channel ch2 device type disk; sql ' alter system archive log current '; #归档当前日志 backup database format '/home/oracle/backup/db_%d_%t_%u '; #备份数据文件sql ' alter system Archive log current '; backup archivelog all format '/home/oracle/ backup/arch_%t_%s ' delete all input; #备份归档文件backup format '/home/ Oracle/backup/con_%s_%p ' current controlfile; #备份控制文件crosscheck backup; crosscheck archivelog all; delete noprompt expired backup; delete noprompt obsolete; delete noprompt backup of database completed before ' Sysdate -15 '; #删除15天之前的数据库备份集delete noprompt archivelog all; delete noprompt backup of archivelog all completed before ' Sysdate -15 '; #删除15天之前的归档备份集release channel ch1; release channel ch2; } eof
2. Incremental backup Script
Level 0 increments
[[Email protected] scripts]$ cat rman_backup_level0.sh source /home/oracle /.bash_profile rman target / log=/home/oracle/backup/backupall_rman.log<<eof run { allocate channel ch1 device type disk; #分配通道 allocate channel ch2 device type disk; sql ' Alter system archive log current '; #归档当前日志 backup incremental level 0 database format '/home/oracle/backup/db_level0_%d_%t_%u '; # Backing up data Files sql ' alter system archive log current '; backup archivelog all format '/home/oracle/backup/arch_level0_%t_%s ' delete all input; #备份归档文件backup format '/home/oracle/backup/con_level0_%s_%p ' current controlfile; #备Document control File Crosscheck backup; crosscheck archivelog all; delete noprompt expired backup; delete noprompt obsolete; delete noprompt backup of database completed before ' sysdate -15 '; #删除15天之前的数据库备份集delete noprompt archivelog all; delete noprompt backup of archivelog all completed before ' sysdate -15 '; # Delete Archive backup sets up to 15 days ago release channel ch1; release channel ch2; } Eof
Level 1 increments
[[Email protected] scripts]$ cat rman_backup_level1.sh source /home/oracle /.bash_profile rman target / log=/home/oracle/backup/backupall_rman.log<<eof run { allocate channel ch1 device type disk; #分配通道 allocate channel ch2 device type disk; sql ' Alter system archive log current '; #归档当前日志 backup incremental level 1 database format '/home/oracle/backup/db_level1_%d_%t_%u '; # Backing up data Files sql ' alter system archive log current '; backup archivelog all format '/home/oracle/backup/arch_level1_%t_%s ' delete all input; #备份归档文件backup format '/home/oracle/backup/con_level1_%s_%p ' current controlfile; #备Document control File Crosscheck backup; crosscheck archivelog all; delete noprompt expired backup; delete noprompt obsolete; delete noprompt backup of database completed before ' sysdate -15 '; #删除15天之前的数据库备份集delete noprompt archivelog all; delete noprompt backup of archivelog all completed before ' sysdate -15 '; # Delete Archive backup sets up to 15 days ago release channel ch1; release channel ch2; } Eof
Note:Level 1 backups need to be performed on a level 0 backup basis.
3. Support full standby and incremental backup
[[email protected] scripts]$ cat db_back_rman.sh ##============================ =============================== ## db_bak_rman.sh ## created by robinson ## 2017/12/15 ## usage: db_bak_rman.sh < $ORACLE _sid> < $BACKUP _ level> ## backup_level: ## f: full backup ## 0: level 0 ## 1: level 1 ##============================================================ #!/bin/bash # User specific environment and startup programs if [ -f ~/.bash_profile ]; then . ~/.bash_profile fi ORACLE_SID=${1}; export oracle_sid rman _level=${2}; export rman_level timestamp= ' date +%y%m%d%h%m '; export timestamp date= ' date +%y%m%d '; export DATE rman_dir=/u02/database/${oracle_sid}/backup/rman; export rman_dir RMAN_DATA=${RMAN_DIR}/${DATE}; export RMAN_DATA #RMAN_LOG = $RMAN _data/log; export RMAN_LOG rman_log=/u02/database/${oracle_sid}/backup/rman/log export rman_log # check rman level #================================================================= ===== if [ "$RMAN _level" == "F" ]; then unset incr_lvl backup_type=full else incr_lvl= "Incremental level ${rman_level}" backup_type=lev${rman_level} fi rman_file=${ rman_data}/${oracle_sid}_${backup_type}_${timestamp}; export rman_file ssh_log=${rman_log}/${oracle_sid}_${backup_type}_${timestamp}.log; export SSH_LOG MAXPIECESIZE=4G; export MAXPIECESIZE #Check rman backup path #================= ======================================================== if ! test -d ${RMAN_DATA} then mkdir -p ${RMAN_DATA} fi echo "---------------------------------" >>${SSH_LOG} echo " " >>${SSH_LOG} echo " rman begin to working ... " >>${SSH_LOG} echo " Begin time at: " ' date ' --' date +%y%m%d%h%m ' >>${SSH_LOG} #Startup rman to backup #============================================================================= $ORACLE _home/bin/rman log=${rman _file}.log <<eof connect target / run { configure retention policy to recovery window of 3 days; configure BACKUP OPTIMIZATION ON; CONFIGURE CONTROLFILE AUTOBACKUP ON; configure controlfile autobackup format for device type disk to ' ${rman_file}_%f '; allocate channel ' ch1 ' type disk maxpiecesize=${ maxpiecesize}; allocate channel ' CH2 ' type disk maxpiecesize=${ Maxpiecesize}; set limit channel ch1 readrate=10240; set limit channel ch1 kbytes=4096000; set limit channel ch2 readrate= 10240; set limit&nBsp;channel ch2 kbytes=4096000; crosscheck archivelog all; delete NOPROMPT EXPIRED ARCHIVELOG ALL; BACKUP #AS compressed BACKUPSET ${INCR_LVL} DATABASE FORMAT ' ${rman_file}_%u ' tag ' ${oracle_sid}_${backup_type}_${timestamp} '; sql ' alter system archive Log current '; backup archivelog all format ' ${RMAN_FILE}_arc_%U ' TAG ' ${oracle_sid}_arc_${timestamp} ' delete input; delete noprompt OBSOLETE; RELEASE CHANNEL ch1; RELEASE CHANNEL ch2; } sql "alter database backup controlfile to " ${rman_data}/cntl _${backup_type}.bak ""; exit; eof rc=$? cat ${ Rman_file}.log >>${ssh_log} echo "Rman stop working @ time:" ' Date ' ' date +%y%m%d%h%m ' >>${SSH_LOG} echo >>${SSH_LOG} echo "----------- ------------- >>${SSH_LOG} echo ------ Disk Space ------ >>${ssh_log} df -h >>${ssh_log} echo >>${ ssh_log} if [ $RC -ne "0" ]; then echo "------ error ------" >>${SSH_LOG} else echo "------ no error found during rman backup peroid------" >>${ssh_log} rm -rf ${rman_file}. log fi #Remove old backup than 3 days #= =========================================================================== rmdir=${rman_dir}/'/bin/date +%Y%m%d -d "3 days ago" '; export rmdir echo >>${ssh_log} echo -e "------remove old backup than 3 days ------\ n" >>${SSH_LOG} if test -d ${RMDIR} then rm -rf ${RMDIR} rc=$? fi echo >>${ssh_log} if [ $RC -ne "0" ]; then echo -e "------ remove old backup exception------ \n " >>${SSH_LOG} else echo -e "------ no error found during remove old backup set peroid------ \n " >>${ssh_log} fi exit
Rman Backup Script Shell version