Tuesday, August 13, 2013

Limitation of 11g ASMCMD cp command

The below script can be used to automate and overcome the limitation of 11g ASMCMD cp command.

Limitation
The new cp (copy) command introduced in 11g asmcmd tool has limitation that it cannot copy a directory nor multiple files at a time using the cp command from asmcmd prompt.

Solution
I have written the below shell script that can be scheduled to copy multiple files for example from the FRA's autobackup directory from ASM to local disk using the asmcmd utility.

You can schedule the below script in crontab as grid user.

#multiplefilecopyfromasmtodisk.sh
#!/bin/bash

#
# This script copies files from FRA on ASM to local disk
#
PATH=/u01/oragrid/11.2.0.2/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH; export PATH
ORACLE_SID=+ASM1; export ORACLE_SID
ORACLE_HOME=/u01/oragrid/11.2.0.3; export ORACLE_HOME
ASMLS=/u01/autobackupControlFile/asm_ls.txt; export ASMLS
FRA=+FRA1/ORCL/AUTOBACKUP/`date +%Y_%m_%d`; export FRA
LOCALBACKUPDIR=/u01/autobackupControlFile; export LOCALBACKUPDIR
LOG=/u01/autobackupControlFile/filecopyfromasm.log; export LOG
#
# Get the list of files
#
cd /u01/oragrid/11.2.0.2/bin/
./asmcmd > $ASMLS <
ls $FRA
exit
EOF
#
# Clean the list by removing "ASMCDM>"
#
sed -i 's/ASMCMD> //g' $ASMLS
cat $ASMLS
echo `date` > $LOG
#
# Copy files one by one
#
for FILENAME in `cat $ASMLS`
do
./asmcmd >> $LOG <
cp $FRA/$FILENAME $LOCALBACKUPDIR
EOF
done
cat $LOG

Reference
I recently attended 'Advanced Shell Scripting' course in Hyderabad that helped me to write the above script. I hope you find it useful.

For any further help on this topic please email me, samiora@gmail.com