#!/bin/bash
#
# cgbackup
# --------
# utility for creating an online backup of the cego database system
#                                        
# Design and Implementation by Bjoern Lemke               
#     
# (C)opyright 2009 Bjoern Lemke


if [ -z $1 ] || [ -z $2 ]
then
    echo "Usage : cgbackup <tableset> <archpath>"
    exit 1
fi


# please customize the following parameters
TS=$1
ARCHPATH=$2
CGADM=cgadm
USER=cgadm/cgadm
HOST=localhost
PORT=2000
OUTFILE=${ARCHPATH}/bu-`date "+%m%d%Y-%H%M"`.tar
MSG="'hello world'"

### end of customizing ####

echo "Starting backup .."

$CGADM --server=$HOST --port=$PORT --user=$USER --cmd="begin backup for ${TS} message ${MSG};"
if [ $? -ne 0 ]
then
    echo "Start Backup failed"
    exit 1
fi 

echo "Saving files to $OUTFILE .."
tar -cvf $OUTFILE  `$CGADM --server=$HOST --port=$PORT --user=$USER --raw --cmd="list bufile for ${TS}"`

echo "Ending backup .."
$CGADM --server=$HOST --port=$PORT --user=$USER --cmd="end backup for ${TS};"
if [ $? -ne 0 ]
then
    echo "End Backup failed"
    exit 1
fi 

echo "Backup completed."
exit 0

