#!/bin/bash

. ${TOOLKIT}-functions.sh

set -e


setbackupname()
{
    local name=
    local myname=`uname -n`
    local myname_short=`uname -n | sed -e 's/\..*//'`

    jtconf backup.$myname.dirs >/dev/null 2>/dev/null && name="backup.$myname"

    [ "$name" == "" ] && {
	jtconf backup.$myname_short.dirs >/dev/null 2>/dev/null && name="backup.$myname_short"
    }

    [ "$name" == "" ] && {
	for class in xen kvm server laptop
	do
		class_requested $class || continue
		jtconf backup-template.$class.dirs >/dev/null 2>/dev/null || continue
		name="backup-template.$class"
		break
	done
    }

    [ "$name" == "" ] && {
	name="backup"
    }

    echo "  using backup definitions: '$name'" >&2
    echo "$name"
}

file="kubackup-rbackup.conf"
backupname=`setbackupname`

cp $file $file.tmp
desc=`	   jtconf $backupname.desc 2>/dev/null`
dirs=`     jtconf $backupname.dirs`		|| exit_missing_define $backupname.dirs
excludes=` jtconf $backupname.excludes`		|| exit_missing_define $backupname.excludes
saveperms=`jtconf $backupname.saveperms 2>/dev/null`

echo "
# $desc
#
bck_common_excludes='$excludes'
bck_dirs='$dirs'
bck_saveperms='$saveperms'
" >> $file.tmp

exit 0
