
#!/bin/sh
# File	: move_data_to_backup-fs.sh
# By	: Maarten.deBoer@atos.net, 180712
# Subject	: Script to move Graphite data from /appl/data to /appl/backup
PGM=`basename $0|cut -d\. -f1`
VER="0.1"
TMP="/tmp/${PGM}.$$"
DATADIR="/appl/data"
BCKDIR="/appl/backup"
BASEDIR="graphite/storage/whisper/netapp/perf7/nl"
#FILTER="nlnaf2[56]"
FILTER="nlnaf6*"

if [ ! -d ${BCKDIR}/${BASEDIR} ]; then
  echo " Creating dir: ${BCKDIR}/${BASEDIR} ..."
  mkdir -p ${BCKDIR}/${BASEDIR}
fi  # ! -d

## Stopping Carbon 1st. So no data is comming in
#/etc/init.d/carbon-cache stop

cd ${DATADIR}/${BASEDIR}
ls -1d ${FILTER}|while read DIR REST
do
# Check if dir (-d) and not already a s-link (! -h)
  if [ -d ${DIR} ] && [ ! -h ${DIR} ]; then
    echo "${DIR} ..."
    cp -r ${DIR} ${BCKDIR}/${BASEDIR}
    mv ${DIR} ${DIR}.old
    ln -s ${BCKDIR}/${BASEDIR}/${DIR} ${DIR}
    rm -rf ${DIR}.old
  fi  # -d
done  # ls -1

## Starting carbon again
#/etc/init.d/carbon-cache start

exit 0

