#!/bin/bash
#
#  GroupWise DBCopy script
#  WMeens NetEyes v0.2  11 2011
#
# WARNING - BEFORE RUNNING THIS SCRIPT MAKE SURE THE COPY FLOWS FROM LIVE TO RESTORE PATH
#           RUNNING THIS SCRIPT FROM RESTORE TO LIVE WILL CAUSE DATA LOSS IN THE LIVE AREA
#
echo Starting DBCopy procedure > $gwcopypath/grpwisedbcopy.log
date >> $gwcopypath/grpwisedbcopy.log
 
# Replace var paths accordingly
gwlivepath=/media/nss/GWSYS
gwcopypath=/media/nss/GWBCK/RESTORE
dom1loc=/DOMAIN1
po1loc=/PO1
# end var paths
  
#quick check for path contents domain & run copy if found
echo "checking path to live GroupWise dibs..."
if [ -d $gwlivepath$dom1loc ]; then
echo "Directory exists, doing copy..."
 
echo start copy domain dibs >> $gwcopypath/grpwisedbcopy.log
date >> $gwcopypath/grpwisedbcopy.log
# N O T E Make sure $gwlivepath is pointing to the the live area  -  ALWAYS COPY FROM LIVE TO THE RESTORE AREA
echo "DBCopy primary domain.."
/opt/novell/groupwise/agents/bin/dbcopy -d -k $gwlivepath$dom1loc $gwcopypath$dom1loc
echo --end copy domain dibs >> $gwcopypath/grpwisedbcopy.log
date >> $gwcopypath/grpwisedbcopy.log
 
echo Start copy po dibs >> $gwcopypath/grpwisedbcopy.log
date >> $gwcopypath/grpwisedbcopy.log
echo "DBCopy van PO.."
/opt/novell/groupwise/agents/bin/dbcopy -p -k $gwlivepath$po1loc $gwcopypath$po1loc
echo --end copy po dibs >> $gwcopypath/grpwisedbcopy.log
date >> $gwcopypath/grpwisedbcopy.log

echo --  >> $gwcopypath/grpwisedbcopy.log
echo Rsync with delete option for offiles folder restore area - clear attachments that live in live area nomore >> $gwcopypath/grpwisedbcopy.log
rsync --delete --ignore-existing --prune-empty-dirs --recursive $gwlivepath$po1loc/offiles/ $gwcopypath$po1loc/offiles/
rsync --delete --ignore-existing --prune-empty-dirs --recursive $gwlivepath$po1loc/ofuser/index $gwcopypath$po1loc/ofuser/index 
  
#set timestamp to now for PO databases
/opt/novell/groupwise/agents/bin/gwtmstmp -s -p $gwlivepath$po1loc
  
else
echo "Directory does not exists, exit script"
echo --dbcopy GroupWise did not run - path not found to domian >> $gwcopypath/grpwisedbcopy.log
date >> $gwcopypath/grpwisedbcopy.log
fi

echo --end copy script GroupWise restore area >> $gwcopypath/grpwisedbcopy.log
date >> $gwcopypath/grpwisedbcopy.log
 