程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> DB2數據庫 >> DB2教程 >> RMAN--full--incr0--incr1三合一腳本

RMAN--full--incr0--incr1三合一腳本

編輯:DB2教程

RMAN--full--incr0--incr1三合一腳本


 

-h 查看幫助信息

[oracle@gc1 ~]$ sh backup.sh -h
The following information teach you how to use this script
backup.sh --full
backup.sh --incr0 
backup.sh --incr1 
THE is the place where you want to store the backup
After 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 directory 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 information
backup.sh --help
Usage:
backup.sh --full 
backup.sh --incr0 
backup.sh --incr1 
backup.sh --help

#!/bin/bash

cmd=$1
script_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_name --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 backupset"
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.log


local LOGDATE=`date +%Y-%m-%d`
local RMANLOG=$RMAN_HOME/$datedir/log/full_${LOGDATE}.log


if [ ! -d ${RMAN_HOME} ];
then mkdir -p $RMAN_HOME
mkdir $RMAN_HOME/archlog
mkdir $RMAN_HOME/ctlfile
mkdir $RMAN_HOME/data
mkdir $RMAN_HOME/log
mkdir $RMAN_HOME/data/full
fi


if [ ! -f ${LOGFILE} ];
then touch ${LOGFILE}
fi


if [ ! -f ${RMANLOG} ];
then touch ${RMANLOG}
fi
#-------------start backup-----------------


echo "-------------------------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 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 database tag 'fullbackup' filesperset 3 format '$RMAN_HOME/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 channel c5;
}
exit;
EOF


echo "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 file
echo "Full backup complete,your backup are in $RMAN_HOME"
}




incr0() {
#-----------------------script env-----------------------



local LOGFILE=$RMAN_HOME/$datedir/log/dbbak.log


local LOGDATE=`date +%Y-%m-%d`
local RMANLOG=$RMAN_HOME/$datedir/log/incr0_${LOGDATE}.log


if [ ! -d ${RMAN_HOME} ];
then mkdir -p $RMAN_HOME
mkdir $RMAN_HOME/archlog
mkdir $RMAN_HOME/ctlfile
mkdir $RMAN_HOME/data
mkdir $RMAN_HOME/data/incr0
mkdir $RMAN_HOME/log
fi


if [ ! -f ${LOGFILE} ];
then touch ${LOGFILE}
fi


if [ ! -f ${RMANLOG} ];
then touch ${RMANLOG}
fi
#-------------start incr0 backup-----------------


echo "-------------------------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 'incr0backup' filesperset 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 c3;
release channel c4;
release channel c5;
}
exit;
EOF


echo "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 file
echo "Incremental 0 backup complete,your backup are in $RMAN_HOME"
}




incr1() {
#-----------------------script env-----------------------






local LOGFILE=$RMAN_HOME/$datedir/log/dbbak.log


local LOGDATE=`date +%Y-%m-%d`
local RMANLOG=$RMAN_HOME/$datedir/log/incr1_${LOGDATE}.log


if [ ! -d ${RMAN_HOME} ];
then mkdir -p $RMAN_HOME
mkdir $RMAN_HOME/archlog
mkdir $RMAN_HOME/ctlfile
mkdir $RMAN_HOME/data
mkdir $RMAN_HOME/data/incr1
mkdir $RMAN_HOME/log
fi


if [ ! -f ${LOGFILE} ];
then touch ${LOGFILE}
fi


if [ ! -f ${RMANLOG} ];
then touch ${RMANLOG}
fi
#-------------start incr1 backup-----------------


echo "-------------------------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 'incr1backup' filesperset 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 c3;
release channel c4;
release channel c5;
}
exit;
EOF


echo "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 file
echo "Incremental 1 backup complete,your backup are in $RMAN_HOME"
}


case "$cmd" in
--help)
print_help
;;
-h)
print_help
;;
--h)
print_help
;;
--full)
full
;;
--incr0)
incr0
;;
--incr1)
incr1
;;
esac

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved