Benutzer-Werkzeuge

Webseiten-Werkzeuge


dba:rman_script01

Beispiele für ein RMAN Script

Über ein zentrales Script werden allen Datenbanken auf dem Host einzeln gesichert.

Ein zentrales Script für die Sicherung der Oracle Datenbank (Single Instance / ASM Umgebungen / RAC) finden Sie hier: OraPowerShell Bash Backup Scripts

Mit diesen Scripts wird nicht nur die DB, sonder je nach Bedarf auch weitere Einstellungen und Konfigurationen von einer RAC oder ASM Umgebung.


Alte manuelle Version zu Informationszwecken

Aufruf:

  • backup.sh mit einem Eintrag auf die runRMAN.sh pro DB
  • runRMAN.sh ruft eigentliche RMAN Sicherung auf, sichert Traces vom Controlfile und spfile
  • info.sql spoolt metadaten aus der DB

OS:Unix
DB:11g

runBackup.sh
#!/bin/sh
# Enviroment
DAY_OF_WEEK="`date +%w`"
export DAY_OF_WEEK
DAY="`date +%d`"
export DAY
 
SCRIPTS=/home/oracle/backup
export SCRIPTS
 
BACKUP_DEST=/backuptest/flash_recovery_area
export BACKUP_DEST
 
if [ ! -d ${BACKUP_DEST} ]; then
   echo "Backup Directory ${BACKUP_DEST} not exist"
   echo " "
   exit 2
fi
 
if [ ! -d ${SCRIPTS} ]; then
   echo "Script Directory ${SCRIPTS} not exist"
   echo " "
   exit 3
fi
 
echo ------------- START BACKUP V1 at "`date`" ----  -------------- > "${SCRIPTS}/backup_${DAY_OF_WEEK}.log" 2>&1
 
## Start Backup for each DB
## Parameter ORACLE_HOME ORACLE_SID ORACLE_DBNAME NLS_LANG
 
${SCRIPTS}/runRMAN.sh /u01/app/oracle/product/11.2.0/dbhome_1 gpi1 GPI .UTF8 >> "${SCRIPTS}/backup_${DAY_OF_WEEK}.log" 2>&1
 
 
echo ------------- Finish BACKUP V1 at "`date`" ------------------ >> "${SCRIPTS}/backup_${DAY_OF_WEEK}.log" 2>&1
runRMAN.sh
#!/bin/sh
# Parameter
ORACLE_HOME=$1
export ORACLE_HOME
ORACLE_SID=$2
export ORACLE_SID
ORACLE_DBNAME=$3
export ORACLE_DBNAME
NLS_LANG=$4
export NLS_LANG
 
# Test Parameter
if [ "$4" = ""  ]; then
   echo "Syntax: $f ORACLE_HOME ORACLE_SID ORACLE_DBNAME NLS_LANG"
   echo " "
   echo " "
   exit 2
fi
if [ ! -d $1 ]; then
   echo "Directory ORACLE_HOME=$1 not exist"
   echo " "
   exit 3
fi
if [ ! -d ${BACKUP_DEST}/${ORACLE_DBNAME} ]; then
   echo "Backup Directory ${BACKUP_DEST}/${ORACLE_DBNAME} not exist"
   echo " "
   exit 4
fi
 
#Enviroment for execute as cronjob
LD_LIBRARY_PATH=$ORACLE_HOME/lib32:$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
 
# Run RMAN Script for this DB
 
#${ORACLE_HOME}/bin/rman target / nocatalog @${SCRIPTS}/backup.rman
 
# Delete old Trace of Controlfile
 
rm ${BACKUP_DEST}/${ORACLE_DBNAME}/controlfile_trace_${DAY_OF_WEEK}.trc
 
# Run Script to generate Trace of Controlfile
# Run Script to generate Copy of pfile
 
${ORACLE_HOME}/bin/sqlplus / as sysdba << EOScipt
ALTER DATABASE backup controlfile TO trace AS '${BACKUP_DEST}/${ORACLE_DBNAME}/controlfile_trace_${DAY_OF_WEEK}.trc';
CREATE pfile='${BACKUP_DEST}/${ORACLE_DBNAME}/init_${ORACLE_DBNAME}_${DAY_OF_WEEK}.ora' FROM spfile;
exit;
EOScipt
 
#Run Script to get DB Metadata Information
 
${ORACLE_HOME}/bin/sqlplus / as sysdba @${SCRIPTS}/info.sql
 
#PatchLevel of the database
 
$ORACLE_HOME/OPatch/opatch lsinventory > ${BACKUP_DEST}/${ORACLE_DBNAME}/software_lsinventory_${ORACLE_DBNAME}.log
 
#Save Password File
cp ${ORACLE_HOME}/dbs/orapw${ORACLE_SID} ${BACKUP_DEST}/${ORACLE_DBNAME}/orapw${ORACLE_SID}_${DAY_OF_WEEK}
backup.rman
# SET Config
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE MAXSETSIZE TO 10G;
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET;
 
SHOW ALL;
 
# test old backup 
crosscheck backup;
DELETE noprompt EXPIRED backup;
crosscheck archivelog ALL;
DELETE noprompt EXPIRED archivelog ALL;
 
#Backup DB
SQL "alter system checkpoint";  
backup incremental LEVEL 0 tag "full_backup" DATABASE;
 
#Backup archivelogs 
SQL "alter system archive log current";
backup archivelog ALL tag "archive_backup" DELETE input;
 
#Delete old Backups
DELETE noprompt obsolete; 
#Backup controlfile AND spfile 
backup CURRENT controlfile tag "controlfile_backup";
backup spfile tag "spfile_backup";
 
 
 
#Summary info
list backup summary; 
info.sql
spool ${BACKUP_DEST}/${ORACLE_DBNAME}/dbinfo_${ORACLE_SID}_${DAY_OF_WEEK}.LOG
SET pagesize 200
column name format a60
column parameter format a40
column VALUE format a30
column property_value format a30
column property_name format a30
column tablespace_name format a20
column FLASHBACK_ON format a40
column LOG_MODE format a20
---------------- version --------------------
ttitle  "#########################version#########################"  skip 2
SELECT * FROM v$version;
SELECT * FROM v$option;
SELECT 
 
---------------- patchlevel --------------------
ttitle  "#########################patchlevel#########################"  skip 2
SELECT * FROM sys.registry$history;
 
---------------- properties --------------------
ttitle  "#########################properties#########################"  skip 2
SELECT property_name,property_value FROM database_properties;
 
---------------- charset -------------------
ttitle  "#########################charset#########################"  skip 2
SELECT * FROM nls_database_parameters;
 
-------------- dbid ------------------------
ttitle  "#########################dbid#########################"  skip 2
SELECT name,dbid FROM v$database;
 
-------------- datastructur ---------------
ttitle  "#########################datastructur#########################"  skip 2
SELECT name AS datafile_name FROM v$datafile;
SELECT name AS tempfile_name FROM v$tempfile;
SELECT member AS logfile_name FROM v$logfile;
SELECT tablespace_name,block_size FROM dba_tablespaces ORDER BY tablespace_name;
 
------ archive -----------------------------
ttitle  "#########################archive and flashback#########################"  skip 2
 
archive LOG list
 
SELECT FLASHBACK_ON,LOG_MODE FROM v$database;
 
spool off
EXIT;
Cookies helfen bei der Bereitstellung von Inhalten. Durch die Nutzung dieser Seiten erklären Sie sich damit einverstanden, dass Cookies auf Ihrem Rechner gespeichert werden. Weitere Information
"Autor: Gunther Pipperr"
dba/rman_script01.txt · Zuletzt geändert: 2013/09/11 13:55 von Gunther Pippèrr