Wednesday 7 December 2011

ASMCMD Wrapper ... For the Frequent ASM Administrator

In the pre-11g days of ASM, I was hesitant to use ASMCMD (command line utility to perform ASM tasks)... perhaps in its earlier days, it was a combination of limited functionality and my comfort in connecting to the ASM instance via sqlplus to perform administrative tasks.

But now in 11g, I have grown the desire to use ASMCMD and have found it to be more useful then I have first envisaged. In 11g, some of the new functionality now offered through ASMCMD includes the ability to perform: startup and shutdown of ASM instance backup (md_backup) and restore (md_restore) of asm metadata list open files (lsof) verify disk usage (du) change/alter (chdg) disks in disk groups.   For a comprehensive list of ASMCMD commands, you can refer to Oracle 11.2 Database Storage Administrator's Guide.

With the more frequent use of ASMCMD, I got tired of switching between the ASM environment and DB environment settings, as a result, I have created an ASM wrapper script which calls asmcmd (ie. works when ASM is mounted or running) with the ability to preserve your DB environment setting. 

Example of using this script are provided below:

NOTE: Change to the directory to where the script sos_asm.sh was downloaded to and set executable permission accordingly
[oracle@lnx01] cd /home/oracle/scripts
[oracle@lnx01] chmod +x sos_asm.sh
Example 1:
Using the sos_asm.sh script, I performed an ASM metadata backup using asmcmd but also was able to preserve database environment settings for the database called BLUE.
[oracle@lnx01] export ORACLE_SID=BLUE; . oraenv
[oracle@lnx01] cd /home/oracle/scripts
[oracle@lnx01] ./sos_asm.sh md_backup /home/oracle/asm_backup/dgbk_DG_DATA -G DG_DATA
[oracle@lnx01] sqlplus / as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Wed Jul 20 23:09:31 2011
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select sys_context('USERENV','DB_NAME') DB from dual;
DB
-----------
BLUE