# RMAN Backup on Linux
- Create a backup directory.
mkdir -p /rmanbackup/rmanlog | |
mkdir -p /rmanbackup/dbbak | |
mkdir -p /rmanbackup/scripts | |
mkdir -p /rmanbackup/week | |
mkdir -p /rmanbackup/day | |
chown -R oracle:oinstall /rmanbackup | |
chmod -R 755 /rmanbackup |
- Create a full backup script: /rmanbackup/scripts/rmanbackup.sh
#/bin/env bash | |
export ORACLE_BASE=/u01/app/oracle | |
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 | |
export ORACLE_OWNER=oracle | |
export ORACLE_SID=orcl1 | |
export ORACLE_UNQNAME=orcl | |
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/bin | |
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib:/lib:/usr/lib | |
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib | |
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK | |
export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS" | |
today=`date +%Y-%m-%d` | |
# Delete expired backup that 7 days old | |
find /rmanbackup/dbbak/ -name "*full*" -mtime +7 -exec rm {} \; | |
find /rmanbackup/dbbak/ -name "*archivelog*" -mtime +7 -exec rm {} \; | |
find /rmanbackup/dbbak/ -name "controlfile*" -mtime +7 -exec rm {} \; | |
find /rmanbackup/dbbak/ -name "spfile*" -mtime +7 -exec rm {} \; | |
# Full backup | |
rman target / nocatalog log /rmanbackup/rmanlog/rmanbk_$today.log append <<EOF | |
run { | |
crosscheck backup; | |
delete noprompt expired backup; | |
allocate channel c1 device type disk; | |
allocate channel c2 device type disk; | |
allocate channel c3 device type disk; | |
allocate channel c4 device type disk; | |
backup as compressed backupset format '/rmanbackup/dbbak/orcl_full_%T_%d_%s_%p_%u.dbf' database plus archivelog; | |
sql 'alter system archive log current'; | |
delete noprompt archivelog until time 'sysdate-7'; | |
backup current controlfile format '/rmanbackup/dbbak/controlfile_%T_%U_%t.crl'; | |
backup spfile format '/rmanbackup/dbbak/spfile_%T_%U_%t.ora'; | |
release channel c1; | |
release channel c2; | |
release channel c3; | |
release channel c4; | |
} | |
quit | |
EOF |
- Create a level 0 incremental backup script: /rmanbackup/scripts/rman_0_level_full.sh
#/bin/bash | |
export ORACLE_BASE=/u01/app/oracle | |
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 | |
export ORACLE_OWNER=oracle | |
export ORACLE_SID=orcl1 | |
export ORACLE_UNQNAME=orcl | |
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/bin | |
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib:/lib:/usr/lib | |
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib | |
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK | |
export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS" | |
today=`date +%Y-%m-%d` | |
# Delete expired backup that 7 days old | |
find /rmanbackup/week/ -name "*full*" -mtime +7 -exec rm {} \; | |
find /rmanbackup/week/ -name "*arch*" -mtime +7 -exec rm {} \; | |
find /rmanbackup/week/ -name "ctl*" -mtime +7 -exec rm {} \; | |
find /rmanbackup/week/ -name "spfile*" -mtime +7 -exec rm {} \; | |
# Level 0 incremental backup | |
rman target / nocatalog log /rmanbackup/rmanlog/fullback0_$today.log <<EOF | |
run{ | |
crosscheck backup; | |
delete noprompt expired backup; | |
allocate channel d1 type disk; | |
allocate channel d2 type disk; | |
allocate channel d3 type disk; | |
allocate channel d4 type disk; | |
backup incremental level 0 as compressed backupset database format '/rmanbackup/week/orcl_full0_%d_%T_%t_%s_%p'; | |
sql 'alter system archive log current'; | |
backup as compressed backupset filesperset 10 format '/rmanbackup/week/arch_%d_%T_%t_%s_%p' archivelog all; | |
backup current controlfile format '/rmanbackup/week/ctl_%d_%T_%t_%s_%p'; | |
backup spfile format '/rmanbackup/week/spfile_%T_%U_%t.ora'; | |
release channel d1; | |
release channel d2; | |
release channel d3; | |
release channel d4; | |
} | |
quit | |
EOF |
- Create a level 1 incremental backup script: /rmanbackup/scripts/rman_1_level_incremental.sh
#/bin/bash | |
export ORACLE_BASE=/u01/app/oracle | |
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 | |
export ORACLE_OWNER=oracle | |
export ORACLE_SID=orcl1 | |
export ORACLE_UNQNAME=orcl | |
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/bin | |
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib:/lib:/usr/lib | |
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib | |
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK | |
export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS" | |
today=`date +%Y-%m-%d` | |
# Delete expired backup that 7 days old | |
find /rmanbackup/day/ -name "*full*" -mtime +7 -exec rm {} \; | |
find /rmanbackup/day/ -name "*arch*" -mtime +7 -exec rm {} \; | |
find /rmanbackup/day/ -name "ctl*" -mtime +7 -exec rm {} \; | |
find /rmanbackup/day/ -name "spfile*" -mtime +7 -exec rm {} \; | |
# Level 1 incremental backup | |
rman target / nocatalog log /rmanbackup/rmanlog/incrementback1_$today.log <<EOF | |
run{ | |
crosscheck backup; | |
delete noprompt expired backup; | |
allocate channel d1 type disk; | |
allocate channel d2 type disk; | |
allocate channel d3 type disk; | |
allocate channel d4 type disk; | |
backup incremental level 1 as compressed backupset database format '/rmanbackup/day/increment1_%d_%T_%t_%s_%p'; | |
sql 'alter system archive log current'; | |
backup as compressed backupset filesperset 10 format '/rmanbackup/day/arch_%d_%T_%t_%s_%p' archivelog all; | |
backup current controlfile format '/rmanbackup/day/ctl_%d_%T_%t_%s_%p'; | |
backup spfile format '/rmanbackup/day/spfile_%T_%U_%t.ora'; | |
release channel d1; | |
release channel d2; | |
release channel d3; | |
release channel d4; | |
} | |
quit | |
EOF |