Posted by John Hallas on June 11, 2009
This script was written by a colleague James Hardaker.
Creates a backup directory if required, works out the ASM SID, renames the previous entry, then loops round backing up the metadata data for each diskgroup. It also lists each file backed up which is quite helpful.
Finally it creates error checking and a log and error file outputs
003
| # Date Version Author Comments
|
004
| # 09/06/09 1.1 Initial Version
|
005
| # 10/06/09 1.2 Added Error Handling
|
006
| #
|
009
| # Queries ASM for a list of disk groups and backs up the metadata of each to /app/oracle/backups
|
010
| # Should be run as the oracle user
|
015
| BACKUPDIR=/app/oracle/backups
|
016
| |
019
| ##########
|
020
| # Start of functions
|
021
| #
|
022
| # asm_metadata - backup the asm metadata
|
025
|
|
026
| export ORACLE_SID=`cat /etc/oratab | grep ^+ASM | awk '{FS=":"} {print $1} ' `
|
027
| export ORACLE_HOME=`cat /etc/oratab | grep ^+ASM | awk '{FS=":"} {print $2} ' `
|
028
| |
029
| for DG in `asmcmd ls + | sed 's/\///'`
|
030
| do
|
031
| echo "INFO: Backup of ${DG} diskgroup started at `date`"
|
032
| if [ -f ${BACKUPDIR}/asm_metadata_${DG}.bkp ] |
033
| then
|
034
| echo "INFO: Moving the file ${BACKUPDIR}/asm_metadata_${DG}.bkp to ${BACKUPDIR}/asm_metadata_${DG}.old" |
035
| cp ${BACKUPDIR}/asm_metadata_${DG}.bkp ${BACKUPDIR}/asm_metadata_${DG}.old 2>/dev/null
|
036
| if [ $? -ne 0 ] |
037
| then
|
038
| echo "WARN: Unable to backup ${BACKUPDIR}/asm_metadata_${DG}.bkp, will overwrite it anyway" |
039
| fi
|
040
| rm -f ${BACKUPDIR}/asm_metadata_${DG}.bkp 2>/dev/null |
041
| fi
|
042
| echo "INFO: Backing up the ${DG} diskgroup to ${BACKUPDIR}/asm_metadata_${DG}.bkp" |
043
| rm ${BACKUPDIR}/asm_metadata_${DG}.err 2>/dev/null
|
044
| ${ORACLE_HOME}/bin/asmcmd md_backup -b ${BACKUPDIR}/asm_metadata_${DG}.bkp -g ${DG} 2>${BACKUPDIR}/asm_metadata_${DG}.err |
045
| if [ -s ${BACKUPDIR}/asm_metadata_${DG}.err ]
|
046
| then |
047
| echo ""
|
048
| echo "WARN: Unable to backup the ${DG} diskgroup to ${BACKUPDIR}/asm_metadata_${DG}.bkp" |
049
| cat ${BACKUPDIR}/asm_metadata_${DG}.err
|
050
| echo "" |
053
| echo "INFO: Backup of ${DG} diskgroup completed at `date`"
|
054
| fi |
059
| ##########
|
060
| # End of functions
|
063
|
|
064
| echo "INFO: ASM Metadata backup started at `date`"
|
065
| echo ""
|
066
| echo "INFO: This script is being run as user `/usr/bin/id -un`"
|
069
| # create the backup directory if it does not exist
|
070
| #
|
071
|
|
072
| if [ ! -d ${BACKUPDIR} ]
|
073
| then
|
074
| mkdir ${BACKUPDIR} 2>/dev/null |
075
| echo "INFO: Created the directory ${BACKUPDIR} as it did not exist"
|
076
| echo "" |
077
| if [ $? -ne 0 ]
|
078
| then |
079
| echo "ERROR: Unable to create the directory ${BACKUPDIR}"
|
080
| exit 99 |
083
|
|
084
| # backup the asm metadata
|
091
|
|
092
| if [ ${ERR} != 0 ]
|
093
| then
|
094
| echo "ERROR: An error occurred backing up one or more disk groups, see above" |
097
| echo "INFO: ASM Metadata backup completed at `date`"
|
098
| fi
|
A sample output for part of the DATA datagroup looks like this :-
01
| @diskgroup_set = (
|
02
| { |
03
| 'ATTRINFO' => { |
04
| 'AU_SIZE' => '8388608', |
05
| 'DISK_REPAIR_TIME' => '3.6h', |
06
| 'COMPATIBLE.ASM' => '11.1.0.0.0', |
07
| 'COMPATIBLE.RDBMS' => '11.1' |
08
| }, |
09
| 'DISKSINFO' => { |
10
| 'DATA_0036' => { |
11
| 'DATA_0036' => { |
12
| 'TOTAL_MB' => '91136', |
| | | |
13
| 'FAILGROUP' => 'DATA_0036', |
14
| 'NAME' => 'DATA_0036', |
| | |
15
| 'DGNAME' => 'DATA', |
16
| 'PATH' => '/dev/oracle/disk22' |
19
| 'DATA_0006' => { |
20
| 'DATA_0006' => { |
21
| 'TOTAL_MB' => '91136', |
22
| 'FAILGROUP' => 'DATA_0006', |
23
| 'NAME' => 'DATA_0006', |
24
| 'DGNAME' => 'DATA', |
25
| 'PATH' => '/dev/oracle/disk6' |
26
| } |
| | | |
27
| }, |
28
| 'DATA_0069' => { |
29
| 'DATA_0069' => { |
30
| 'TOTAL_MB' => '91136', |
| | | |
31
| 'FAILGROUP' => 'DATA_0069', |
32
| 'NAME' => 'DATA_0069', |
| | |
33
| 'DGNAME' => 'DATA', |
34
| 'PATH' => '/dev/oracle/disk87' |
Breno Tozo
Database Administrator
Atos Origin Brasil
Desk +55 (11) 2183-2382
Fax + 55 (11) 2183-2113
Rua Maria Coelho Aguiar, 215 - Bloco E - 5. Andar
São Paulo / SP - Brazil - CEP: 05804-900