Here is the script I use, but it does a ccmdb dump instead of backup, but either should work.
We have to read in the .profile or .bash_profile to get the path environment populated etc. Which I think is what you are missing.
#!/bin/bash
# directory where backup files go
BkupDir=backups
Unprotect=backups/unprotect.list
# list of databases to backup and number in list.
DatabaseList="db1 db2"
DatabaseCount=9
# number of old backups to save
SaveOldCnt=1
# legato defaults us to root directory
cd /home/ccm_root
case $1 in
'before')
# save old log file
if [ -f $0.log ]; then
mv $0.log $0.log.old
fi
# redirect stdout and stderr to log file
exec > $0.log
exec 2>&1
# legato doesn't read our .profile, so do it here
. ./.bash_profile
date
echo `id`
# set up location for old backups
# we use a separate directory so they can be excluded
# from the backup to tape
OldBkupDir=$BkupDir/old
if [ ! -d $OldBkupDir ]; then
mkdir $OldBkupDir
if [ $? -ne 0 ]; then
echo
echo ERROR: could not create directory $OldBkupDir !!!
echo
OldBkupDir=$BkupDir
fi
fi
if [ ! -w $OldBkupDir ]; then
echo
echo ERROR: directory $OldBkupDir is not writable !!!
echo
OldBkupDir=$BkupDir
fi
# move old backup to the directory for old backups
# (so it doesn't get backed up by tape backup)
for database in ${DatabaseList}
do
if [ $BkupDir != $OldBkupDir ]; then
mv $BkupDir/${database}_2*.dmp $OldBkupDir
fi
# removed old backup files
i=0;
ls -t1 $OldBkupDir/${database}_2*.dmp | while read flnm; do
if [ $i -ge $SaveOldCnt ]; then
rm $flnm
fi
let i=i+1
done
done
for database in ${DatabaseList}
do
# if ccmdb shutdown /ccmdb/$database
if ccmdb protect /ccmdb/$database
then
date
ccmdb dump /ccmdb/${database} -t $BkupDir/${database}.dmp
# rename current backup to include date in name
mv -f $BkupDir/${database}.dmp $BkupDir/${database}_`date +%Y.%m.%d_
%H.%M`.dmp;
date
else
echo "Failed shutdown on ${database}"
fi
done
date
for database in ${DatabaseList}
do
ccmdb unprotect /ccmdb/$database
done
;;
'after')
exec >> $0.log
exec 2>&1
# legato doesn't read our .profile, so do it here
. ./.bash_profile
date
# this is the list that passed the check command, the ones that fail
# will stay protected. To fix the next morning.
# for database in `cat $Unprotect`
for database in ${DatabaseList}
do
ccmdb unprotect /ccmdb/$database
done
# if [ $DatabaseCount -ne `wc -l <$Unprotect` ]; then
# echo "Error some Database(s) did not get unprotected!"
# cat $Unprotect
# echo "Have been unprotected."
# email results
# mailx -s "ERROR `hostname`: $0 results" ccmadmin < $0.log
# else
# email results
mailx -s "`hostname`: $0 results" ccmadmin < $0.log
# fi
date
;;
*)
echo "Usage: dumptest.sh {before|after}"
;;
esac
# legato needs this
exit 0