RMAN -- full -- incr0 -- incr1 three-in-one script
-H: View help information [oracle @ gc1 ~] $ Sh backup. sh-hThe following information teach you how to use this scriptbackup. sh -- fullbackup. sh -- incr0 backup. sh -- incr1 THE is the place where you want to store the backupAfter you set the RMAN_HOME, The script will create the following directory: -- 2015_06_01 | -- archlog -- This directory store your archivelog backup | -- ctlfile -- This directory store your controlfile bakcup | -- data -- This di Rectory store your backup | -- incr0 -- This is your incr0 backupset -- log -- This is your backup log directory | -- dbbak. log -- This log records the backup start and finish time points | -- incr0_2015-06-01.log -- This your backup log records the rman output informationbackup. sh -- helpUsage: backup. sh -- full backup. sh -- incr0 backup. sh -- incr1 backup. sh -- help #! /Bin/bashcmd = $ 1script_name = 'basename $ 0' RMAN _ HOME = $2/'date + % Y _ % m _ % d' print _ usage () {echo "Usage:" echo "$ script_name -- full" echo "$ script_name -- incr0" echo "$ script_name -- incr1" echo "$ script_name -- help"} print_help () {echo "The script was written by FAN" echo "The following information teach you how to use this script" echo "$ script_name -- full" echo "$ script_name -- incr0" echo "$ script_nam E -- incr1 "echo" THE is the place where you want to store the backup "echo" After you set the RMAN_HOME, The script will create the following directory: "echo" -- 2015_06_01 "echo" | -- archlog -- This directory store your archivelog backup "echo" | -- ctlfile -- This directory store your controlfile bakcup "echo" | -- data -- This directory store your backup "echo" | -- incr0 -- This is your incr0 ba Ckupset "echo" -- log -- This is your backup log directory "echo" | -- dbbak. log -- This log records the backup start and finish time points "echo" | -- incr0_2015-06-01.log -- This your backup log records the rman output information "echo" $ script_name -- help "print_usage} full () {# ----------------------- script env ----------------------- local LOGFILE = $ RMAN_HOME/$ datedir/log/dbbak. loglocal LOGDATE = 'date + % Y-% m-% d' local RMANLOG = $ RMAN_HOME/$ datedir/log/full _ $ {LOGDATE}. logif [! -D $ {RMAN_HOME}]; then mkdir-p $ region $ RMAN_HOME/archlogmkdir $ RMAN_HOME/region $ RMAN_HOME/datamkdir $ RMAN_HOME/logmkdir $ RMAN_HOME/data/fullfiif [! -F $ {LOGFILE}]; then touch $ {LOGFILE} fiif [! -F $ {RMANLOG}]; then touch $ {RMANLOG} fi # --------------- start backup ----------------- echo "Restore Rman full backup -----------------------" >$ {LOGFILE} echo "backup_full start time: "'date + % Y-% m-% d _ % H: % M: % s' >>$ {LOGFILE} echo "---------------------- Rman Database backup_full ------------" 'date + % Y-% m-% d _ % H: % M: % s' >$ {RMANLOG} $ ORACLE_HOME/bin/rman target/<>$ {RMANLOG} run {delete n Oprompt obsolete; crosscheck archivelog all; delete noprompt expired archivelog all; allocate channel c1 type disk Category 5g; allocate channel c2 type disk Category 5g; allocate channel c3 type disk MAXPIECESIZE 5g; allocate channel c4 type disk MAXPIECESIZE 5g; allocate channel c5 type disk MAXPIECESIZE 5g; backup as compressed backupset database tag 'fullbackup' filesperset 3 format' $ RMAN_HOM E/data/full/db_full _ % T _ % d _ % t _ % s _ % p. rbck 'include current controlfile; backup as compressed backupset format' $ RMAN_HOME/archlog/arch_full _ % T _ % d _ % t _ % s _ % p. rbck 'archivelog all delete input; backup current controlfile format' $ RMAN_HOME/ctlfile/ctl _ % d _ % T _ % s _ % p _ % t. rbck '; crosscheck backup; delete noprompt expired backup; release channel c1; release channel c2; release channel c3; release channel c4; release ch Annel c5;} exit; EOFecho "backup_full finish! Check in: "$ {RMANLOG >>$ {LOGFILE} echo" backup_full end time: "'date + % Y-% m-% d _ % H: % M: % s' >>$ {LOGFILE} echo "--------------------------------- full_end -------------------------------------" >$ {LOGFILE} # end of fileecho "Full backup complete, your backup are in $ RMAN_HOME "} incr0 () {# ------------------------- script env ----------------------- local LOGFILE = $ RMAN_HOME/$ datedir/log/dbbak. loglocal LOGDATE = 'dat E + % Y-% m-% d' local RMANLOG = $ RMAN_HOME/$ datedir/log/incr0 _ $ {LOGDATE}. logif [! -D $ {RMAN_HOME}]; then mkdir-p $ users $ RMAN_HOME/archlogmkdir $ RMAN_HOME/ctlfilemkdir $ RMAN_HOME/datamkdir $ RMAN_HOME/data/users $ RMAN_HOME/logfiif [! -F $ {LOGFILE}]; then touch $ {LOGFILE} fiif [! -F $ {RMANLOG}]; then touch $ {RMANLOG} fi # --------------- start incr0 backup ----------------- echo "restart Rman incr0 backup -----------------------" >$ {LOGFILE} echo "backup_incr0 start time: "'date + % Y-% m-% d _ % H: % M: % s' >>$ {LOGFILE} echo "---------------------- Rman Database backup_incr0 ------------" 'date + % Y-% m-% d _ % H: % M: % s' >$ {RMANLOG} $ ORACLE_HOME/bin/rman target/<>$ {RMANLOG} run {Delete noprompt obsolete; crosscheck archivelog all; delete noprompt expired archivelog all; allocate channel c1 type disk MAXPIECESIZE 5g; allocate channel c2 type disk MAXPIECESIZE 5g; allocate channel c3 type disk MAXPIECESIZE 5g; allocate channel c4 type disk MAXPIECESIZE 5g; allocate channel c5 type disk MAXPIECESIZE 5g; backup as compressed backupset incremental level 0 database tag 'encr0backup 'f Ilesperset 3 format' $ RMAN_HOME/data/incr0/db_full _ % T _ % d _ % t _ % s _ % p. rbck 'include current controlfile; backup as compressed backupset format' $ RMAN_HOME/archlog/arch_full _ % T _ % d _ % t _ % s _ % p. rbck 'archivelog all delete input; backup current controlfile format' $ RMAN_HOME/ctlfile/ctl _ % d _ % T _ % s _ % p _ % t. rbck '; crosscheck backup; delete noprompt expired backup; release channel c1; release channel c2; release channel c 3; release channel c4; release channel c5;} exit; EOFecho "backup_incr0 finish! Check in: "$ {RMANLOG >>$ {LOGFILE} echo" backup_incr0 end time: "'date + % Y-% m-% d _ % H: % M: % s' >>$ {LOGFILE} echo "--------------------------------- incr0_end -----------------------------------" >$ {LOGFILE} # end of fileecho "Incremental 0 backup complete, your backup are in $ RMAN_HOME "} incr1 () {# ------------------------- script env ----------------------- local LOGFILE = $ RMAN_HOME/$ datedir/log/dbbak. loglocal L OGDATE = 'date + % Y-% m-% d' local RMANLOG = $ RMAN_HOME/$ datedir/log/incr1 _ $ {LOGDATE}. logif [! -D $ {RMAN_HOME}]; then mkdir-p $ users $ RMAN_HOME/archlogmkdir $ RMAN_HOME/ctlfilemkdir $ RMAN_HOME/datamkdir $ RMAN_HOME/data/users $ RMAN_HOME/logfiif [! -F $ {LOGFILE}]; then touch $ {LOGFILE} fiif [! -F $ {RMANLOG}]; then touch $ {RMANLOG} fi # --------------- start incr1 backup ----------------- echo "restart Rman incr1 backup -----------------------" >$ {LOGFILE} echo "backup_incr1 start time: "'date + % Y-% m-% d _ % H: % M: % s' >>$ {LOGFILE} echo "---------------------- Rman Database backup_incr1 ----------" 'date + % Y-% m-% d _ % H: % M: % s' >$ {RMANLOG} $ ORACLE_HOME/bin/rman target/<>$ {RMANLOG} run {Delete noprompt obsolete; crosscheck archivelog all; delete noprompt expired archivelog all; allocate channel c1 type disk MAXPIECESIZE 5g; allocate channel c2 type disk MAXPIECESIZE 5g; allocate channel c3 type disk MAXPIECESIZE 5g; allocate channel c4 type disk MAXPIECESIZE 5g; allocate channel c5 type disk MAXPIECESIZE 5g; backup as compressed backupset incremental level 1 database tag 'encr1backup 'f Ilesperset 3 format' $ RMAN_HOME/data/incr1/db_full _ % T _ % d _ % t _ % s _ % p. rbck 'include current controlfile; backup as compressed backupset format' $ RMAN_HOME/archlog/arch_full _ % T _ % d _ % t _ % s _ % p. rbck 'archivelog all delete input; backup current controlfile format' $ RMAN_HOME/ctlfile/ctl _ % d _ % T _ % s _ % p _ % t. rbck '; crosscheck backup; delete noprompt expired backup; release channel c1; release channel c2; release channel c 3; release channel c4; release channel c5;} exit; EOFecho "backup_incr1 finish! Check in: "$ {RMANLOG >>$ {LOGFILE} echo" backup_incr1 end time: "'date + % Y-% m-% d _ % H: % M: % s' >>$ {LOGFILE} echo "--------------------------------- incr1_end -------------------------------------" >$ {LOGFILE} # end of fileecho "Incremental 1 backup complete, your backup are in $ RMAN_HOME "} case" $ cmd "in -- help) print_help;-h) print_help; -- full) full ;; -- incr0) incr0; -- incr1) incr1; esac