#!/bin/sh

BACKUPDIR="/var/dhcpd/var/db"
BACKUPFILE="/conf/dhcpleases.tgz"
BACKUPOFF="<dhcpbackup>-1</dhcpbackup>"

if [ "$(grep -c "${BACKUPOFF}" /conf/config.xml)" != "0" ]; then
	rm -f ${BACKUPFILE}
elif [ "${1}" = "restore" ]; then
	if [ -f "${BACKUPFILE}" ]; then
		tar -C / -xzpf "${BACKUPFILE}"
	fi
else
	if [ -d "${BACKUPDIR}" ]; then
		tar -C / -czf "${BACKUPFILE}" ."${BACKUPDIR}"
	fi
fi
