#!/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 ]
then
    echo "Usage : cgbackup <tableset>"
    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

### end of customizing ####

echo "Starting backup .."

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

# raw option, in the meantime, we rather provide method via configured backup manager
# echo "Saving files to $OUTFILE .."
# tar -cvf $OUTFILE  `$CGADM --server=$HOST --port=$PORT --user=$USER --raw --cmd="list bufile for ${TS}"`

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

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

