Wednesday, 30 August 2017

Oracle RMAN Backup script with Example for window Enviroment

Rman backup on disk
--------------
#!/usr/bin/ksh
ORACLE_SID=dastat03
export ORACLE_SID
ORACLE_HOME=`cat /etc/oratab|grep $ORACLE_SID:|cut -f2 -d':'`
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH
dt=$(date +"%d-%b-%Y_%H_%M")
export dt
mkdir -p /backup/rman/$dt/control
mkdir -p /backup/rman/$ORACLE_SID/logs
output=$ORACLE_SID_backup_$dt.log
log_file=/backup/rman/$ORACLE_SID/logs/$output

$ORACLE_HOME/bin/rman target / nocatalog log=$log_file  <<EOF
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 80 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
run {
      allocate channel ch1 type DISK;
      allocate channel ch2 type DISK;
      backup incremental level 0 database format '/backup/rman/${dt}/db_full%d_%s_%p_%t';
      backup archivelog all;
      backup current controlfile format  '/backup/rman/${dt}/control/snapcf_${ORACLE_SID}.f';
      backup spfile format               '/backup/rman/${dt}/control/snapspfile_${ORACLE_SID}.f';
      crosscheck backup;
      crosscheck archivelog all;
      delete noprompt obsolete;
      delete noprompt expired backup;
      release channel ch1;
      release channel ch2;
};
>>EOF


========================================================================

Rman backup on tape


$ hostname
servername
$ pwd
/backup/rman
$ cat rman_backup_tape.sh
#!/usr/bin/ksh
ORACLE_SID=database_SID
export ORACLE_SID
ORACLE_HOME=`cat /etc/oratab|grep $ORACLE_SID:|cut -f2 -d':'`
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH
dt=$(date +"%d-%b-%Y_%H_%M")
export dt
DATESTAMP=`date '+%d-%m-%Y-%H-%M'`
export DATESTAMP
mkdir -p /backup/rman/$dt/control
mkdir -p /backup/rman/$ORACLE_SID/logs
output=$ORACLE_SID_backup_$dt.log
log_file=/backup/rman/$ORACLE_SID/logs/$output
$ORACLE_HOME/bin/rman target / nocatalog log=$log_file @/backup/rman/rman_11g_level0_database_bkp.scr
$ cat /backup/rman/rman_11g_level0_dastap01_bkp.scr
run {
configure retention policy to redundancy 80;
configure backup optimization on;
configure controlfile autobackup on;

set command id to '{$ORACLE_SID}_FULL';
allocate channel t1 type 'SBT_TAPE' parms 'ENV=(TDPO_OPTFILE=/usr/tivoli/tsm/client/oracle/ieo2blptsmp01_ora/tdpo.opt)';
allocate channel t2 type 'SBT_TAPE' parms 'ENV=(TDPO_OPTFILE=/usr/tivoli/tsm/client/oracle/ieo2blptsmp01_ora/tdpo.opt)';
allocate channel t3 type 'SBT_TAPE' parms 'ENV=(TDPO_OPTFILE=/usr/tivoli/tsm/client/oracle/ieo2blptsmp01_ora/tdpo.opt)';
allocate channel t4 type 'SBT_TAPE' parms 'ENV=(TDPO_OPTFILE=/usr/tivoli/tsm/client/oracle/ieo2blptsmp01_ora/tdpo.opt)';
sql 'alter system switch logfile';
crosscheck archivelog all;
      backup current controlfile tag '{$ORACLE_SID}_controlfile' format '/controlfile_%d_%U/';
      backup spfile  tag '{$ORACLE_SID}_spfile' format '/spfile_%d_%U/';
backup as compressed backupset filesperset 4
incremental level 0 tag '{$ORACLE_SID}_backup_db_level_0'
format '/FULL_%d_%U/'
(database);
backup as compressed backupset filesperset 10
 tag '{$ORACLE_SID}_backup_archive'
 format '/Archive_%d_%U/'
 (archivelog all)
archivelog until time 'SYSDATE' delete input ;
DELETE noprompt force ARCHIVELOG ALL BACKED UP 2 TIMES TO DEVICE TYPE sbt;
release channel t1;
release channel t3;
release channel t2;
release channel t4;
}
$



========================


set ORACLE_HOME=e:\app\orasbm\product\11.2.0.4\dbhome_1
set PATH=%ORACLE_HOME%\bin;%PATH%
set ORACLE_SID=EASYDB_MUS
cd E:\DB_SCRIPTS\Backup
rman target / @easydb_mus_full_Yearly.rman log=E:\DB_SCRIPTS\Backup\Logs\easydb_mus_full_Yearly_%date:~4,2%_%date:~7,2%_%date:~10%.log


run
{
allocate channel 'dev_0' type 'sbt_tape' parms 'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=easydb_MUS,OB2BARLIST=easyserver_ORA_easydb_MUS_STDY_FULL_ONLINE_EML_YEARLY) SBT_LIBRARY=C:/PROGRA~1/OmniBack/bin/orasbt.dll';
allocate channel 'dev_1' type 'sbt_tape' parms 'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=easydb_MUS,OB2BARLIST=easyserver_ORA_easydb_MUS_STDY_FULL_ONLINE_EML_YEARLY) SBT_LIBRARY=C:/PROGRA~1/OmniBack/bin/orasbt.dll';
allocate channel 'dev_2' type 'sbt_tape' parms 'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=easydb_MUS,OB2BARLIST=easyserver_ORA_easydb_MUS_STDY_FULL_ONLINE_EML_YEARLY) SBT_LIBRARY=C:/PROGRA~1/OmniBack/bin/orasbt.dll';
allocate channel 'dev_3' type 'sbt_tape' parms 'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=easydb_MUS,OB2BARLIST=easyserver_ORA_easydb_MUS_STDY_FULL_ONLINE_EML_YEARLY) SBT_LIBRARY=C:/PROGRA~1/OmniBack/bin/orasbt.dll';
backup incremental level 0 format 'easyserver_ORA_easydb_MUS_STDY_FULL_ONLINE_EML_YEARLY<easydb_MUS_%s:%t:%p>.dbf' database;
backup format 'easyserver_ORA_easydb_MUS_STDY_FULL_ONLINE_EML_YEARLY<easydb_MUS_%s:%t:%p>.dbf' archivelog all;
delete archivelog all backed up 1 times to device type 'sbt_tape' completed before 'sysdate-1';
backup format 'easyserver_ORA_easydb_MUS_STDY_FULL_ONLINE_EML_YEARLY<easydb_MUS_%s:%t:%p>.dbf' current controlfile;
release channel 'dev_0';
release channel 'dev_1';
release channel 'dev_2';
release channel 'dev_3';
}

=========================


set ORACLE_HOME=e:\app\orasbm\product\11.2.0.4\dbhome_1
set PATH=%ORACLE_HOME%\bin;%PATH%
set ORACLE_SID=easydb_MGS
cd E:\DB_SCRIPTS\Backup
rman target / @easydb_mgs_arch.rman log=E:\DB_SCRIPTS\Backup\Logs\easydb_mgs_arch_%date:~4,2%_%date:~7,2%_%date:~10%.log


run
{
allocate channel 'dev_0' type 'sbt_tape' parms 'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=easydb_MGS,OB2BARLIST=R2_easyserver_ORA_easydb_MGS_STDY_FULL_ONLINE_EML_DAILY_ARCH)  SBT_LIBRARY=C:/PROGRA~1/OmniBack/bin/orasbt.dll';
allocate channel 'dev_1' type 'sbt_tape' parms 'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=easydb_MGS,OB2BARLIST=R2_easyserver_ORA_easydb_MGS_STDY_FULL_ONLINE_EML_DAILY_ARCH) SBT_LIBRARY=C:/PROGRA~1/OmniBack/bin/orasbt.dll';
allocate channel 'dev_2' type 'sbt_tape' parms 'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=easydb_MGS,OB2BARLIST=R2_easyserver_ORA_easydb_MGS_STDY_FULL_ONLINE_EML_DAILY_ARCH)  SBT_LIBRARY=C:/PROGRA~1/OmniBack/bin/orasbt.dll';
allocate channel 'dev_3' type 'sbt_tape' parms 'ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=easydb_MGS,OB2BARLIST=R2_easyserver_ORA_easydb_MGS_STDY_FULL_ONLINE_EML_DAILY_ARCH)  SBT_LIBRARY=C:/PROGRA~1/OmniBack/bin/orasbt.dll';
backup format 'R2_easyserver_ORA_easydb_MGS_STDY_FULL_ONLINE_EML_DAILY_ARCH<easydb_MGS_%s:%t:%p>.dbf' archivelog all;
delete noprompt archivelog all backed up 1 times to device type 'sbt_tape' completed before 'sysdate-1';
backup format 'R2_easyserver_ORA_easydb_MGS_STDY_FULL_ONLINE_EML_DAILY_ARCH<easydb_MGS_%s:%t:%p>.dbf' current controlfile;
release channel 'dev_0';
release channel 'dev_1';
release channel 'dev_2';
release channel 'dev_3';
}

No comments:

Post a Comment