Script to backup ASM metadata
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
#!/bin/sh
#
# Date Version Author Comments
# 09/06/09 1.1 Initial Version
# 10/06/09 1.2 Added Error Handling
#
#
# Description
# Queries ASM for a list of disk groups and backs up the metadata of each to /app/oracle/backups
# Should be run as the oracle user
# Tunables
###
BACKUPDIR=/app/oracle/backups
###
##########
# Start of functions
#
# asm_metadata - backup the asm metadata
asm_metadata()
{
export ORACLE_SID=`cat /etc/oratab | grep ^+ASM | awk '{FS=":"} {print $1} ' `
export ORACLE_HOME=`cat /etc/oratab | grep ^+ASM | awk '{FS=":"} {print $2} ' `
for DG in `asmcmd ls + | sed 's/\///'`
do
echo "INFO: Backup of ${DG} diskgroup started at `date`"
if [ -f ${BACKUPDIR}/asm_metadata_${DG}.bkp ]
then
echo "INFO: Moving the file ${BACKUPDIR}/asm_metadata_${DG}.bkp to ${BACKUPDIR}/asm_metadata_${DG}.old"
cp ${BACKUPDIR}/asm_metadata_${DG}.bkp ${BACKUPDIR}/asm_metadata_${DG}.old 2>/dev/null
if [ $? -ne 0 ]
then
echo "WARN: Unable to backup ${BACKUPDIR}/asm_metadata_${DG}.bkp, will overwrite it anyway"
fi
rm -f ${BACKUPDIR}/asm_metadata_${DG}.bkp 2>/dev/null
fi
echo "INFO: Backing up the ${DG} diskgroup to ${BACKUPDIR}/asm_metadata_${DG}.bkp"
rm ${BACKUPDIR}/asm_metadata_${DG}.err 2>/dev/null
${ORACLE_HOME}/bin/asmcmd md_backup -b ${BACKUPDIR}/asm_metadata_${DG}.bkp -g ${DG} 2>${BACKUPDIR}/asm_metadata_${DG}.err
if [ -s ${BACKUPDIR}/asm_metadata_${DG}.err ]
then
echo ""
echo "WARN: Unable to backup the ${DG} diskgroup to ${BACKUPDIR}/asm_metadata_${DG}.bkp"
cat ${BACKUPDIR}/asm_metadata_${DG}.err
echo ""
ERR=98
else
echo "INFO: Backup of ${DG} diskgroup completed at `date`"
fi
echo ""
done
}
##########
# End of functions
### Main Program
echo "INFO: ASM Metadata backup started at `date`"
echo ""
echo "INFO: This script is being run as user `/usr/bin/id -un`"
echo ""
# create the backup directory if it does not exist
#
if [ ! -d ${BACKUPDIR} ]
then
mkdir ${BACKUPDIR} 2>/dev/null
echo "INFO: Created the directory ${BACKUPDIR} as it did not exist"
echo ""
if [ $? -ne 0 ]
then
echo "ERROR: Unable to create the directory ${BACKUPDIR}"
exit 99
fi
fi
# backup the asm metadata
#
ERR=0
asm_metadata
#Finish
#
if [ ${ERR} != 0 ]
then
echo "ERROR: An error occurred backing up one or more disk groups, see above"
exit 98
else
echo "INFO: ASM Metadata backup completed at `date`"
fi
exit
A sample output for part of the DATA datagroup looks like this :-
@diskgroup_set = (
{
'ATTRINFO' => {
'AU_SIZE' => '8388608',
'DISK_REPAIR_TIME' => '3.6h',
'COMPATIBLE.ASM' => '11.1.0.0.0',
'COMPATIBLE.RDBMS' => '11.1'
},
'DISKSINFO' => {
'DATA_0036' => {
'DATA_0036' => {
'TOTAL_MB' => '91136',
'FAILGROUP' => 'DATA_0036',
'NAME' => 'DATA_0036',
'DGNAME' => 'DATA',
'PATH' => '/dev/oracle/disk22'
}
},
'DATA_0006' => {
'DATA_0006' => {
'TOTAL_MB' => '91136',
'FAILGROUP' => 'DATA_0006',
'NAME' => 'DATA_0006',
'DGNAME' => 'DATA',
'PATH' => '/dev/oracle/disk6'
}
},
'DATA_0069' => {
'DATA_0069' => {
'TOTAL_MB' => '91136',
'FAILGROUP' => 'DATA_0069',
'NAME' => 'DATA_0069',
'DGNAME' => 'DATA',
'PATH' => '/dev/oracle/disk87'
This entry was posted on June 11, 2009 at 7:34 am and is filed under 11g new features, ASM, Oracle. Tagged: asmcmd, backup asm metadata, md_backup, metadata. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Sebastian said
Thanks for sharing
It wont work on all system tho. For example on Solaris there is no /etc/oratab only /var/opt/oracle/oratab
John Hallas said
True, we only use HPUX so I had not tested it elsewhere. However it is pretty easy to modify.
I have worked on Sun/Solaris sites that symbolically link /var/opt/oracle/oratab to /etc/oratab to maintain the same scripts across different Unix servers (and also because so many DBAs are used to looking at /etc/oratab to see what databases are created etc)
John
Ed said
Or the script can me modified to accept a parameter to point where the oratab is
or have a function to check what OS is in place
A good start nonetheless.
Log Buffer #150 | WORDPRESS-TEMPLATES-PLUGINS-RSS | Log Buffer #150 >>> said
[...] slow, in ASM Metadata and Migrating a Database to ASM. He then goes on to share a coworker’s Script to Backup ASM Metadata. J. Arneil shows how to go about Fixing up ASM Disk Header Corruption, should you find yourself in [...]
ASM space marked as internal – use check all repair « Oracle DBA – A lifelong learning experience said
[...] we had nothing in there and we <a href=http://jhdba.wordpress.com/2009/06/11/script-to-backup-asm-metadata/> backup ASM metadata </a> every day then I was happy to go [...]
Nuller said
Thank you for your code. I got some new ideas from that
hajib said
Thank you , very useful
Log Buffer #150: A Carnival of the Vanities for DBA’s said
[...] slow, in ASM Metadata and Migrating a Database to ASM. He then goes on to share a coworker’s Script to Backup ASM Metadata. J. Arneil shows how to go about Fixing up ASM Disk Header Corruption, should you find yourself in [...]