#!/bin/sh

: ${RRDDBPATH:=/var/db/rrd}
: ${CF_CONF_PATH:=/conf}

# Save the rrd databases to the config path.
if [ -d "${RRDDBPATH}" ]; then
	for rrdfile in "${RRDDBPATH}"/*.rrd ; do
		xmlfile="${rrdfile%.rrd}.xml"
		/usr/local/bin/rrdtool dump "$rrdfile" "$xmlfile"
	done
	cd / && tar -czf "${CF_CONF_PATH}"/rrd.tgz -C / "${RRDDBPATH#/}"/*.xml
	rm "${RRDDBPATH}"/*.xml
fi