#! /bin/bash do_backup() { local BACKUPDIR=${BACKUP_DIR}/${COMPONENT_NAME} local CASSANDRA_DATA_DIR=${APIGEE_APP_DATADIR} local SNAPSHOTNAME=$(date +%Y%m%d%H%M%S) local tarball=backup-$(date +%Y.%m.%d,%H.%M.%S).tar.gz mkdir -p $BACKUPDIR || exit 1 #Clear snapshots before the backup notice "INFO: Clearing all the older snapshots before the backup" ${APIGEE_ROOT}/${COMPONENT_NAME}/bin/nodetool -h localhost clearsnapshot #Create snapshot ${APIGEE_ROOT}/${COMPONENT_NAME}/bin/nodetool -h localhost snapshot -t ${SNAPSHOTNAME} if [ $? != 0 ]; then notice "ERROR: could not create Snapshot ${SNAPSHOTNAME}" exit 1 else notice "INFO: created snapshot sucessfully ${SNAPSHOTNAME}" fi #Find and backup the snapshot directories SNAPSHOTS=$(find ${CASSANDRA_DATA_DIR} -name snapshots 2>/dev/null) notice "INFO: Preparing to backup the snapshot directories" tar -h -zcvf ${BACKUPDIR}/${tarball} ${SNAPSHOTS} > /dev/null #Clear snapshots ${APIGEE_ROOT}/${COMPONENT_NAME}/bin/nodetool -h localhost clearsnapshot if [ $? != 0 ]; then notice "ERROR: could not clear Snapshot ${SNAPSHOTNAME}, please clear manually using nodetool clearsnapshot" exit 1 else notice "INFO: clearred snapshot sucessfully ${SNAPSHOTNAME}" fi } "$APIGEE_SERVICE" "$COMPONENT_NAME" status > /dev/null 2>&1 if [ $? -eq 0 ] ; then do_backup "$@" else echo "Cassandra service is not running, hence skipping the backup" fi