#
#   Configuration file for backup - generic Tektelic Backup
#

if [ -z "${SYSTEM_ETC}" ]; then
    . $ROOTACT/lrr/com/system_setting.sh
fi

# directory for storing the backup files
BACKUPDIR=/home/actility/backupact

# info file
BACKUPINFO=$BACKUPDIR/backupact_info

# system files usefull for restoring a functionnal environment
# must be limited to the minimum, it is not intend to save the whole system
# sysconfiglrr.sh is run after restore, several system files are updated
SYSTEMFILES="/etc/ntp.conf"
SYSTEMFILES="$SYSTEMFILES /etc/network/interfaces"


# preBackup function
preBackup()
{
    # doing something to avoid error
    echo "preBackup called" >/dev/null
}

# postBackup function
postBackup()
{
    # doing something to avoid error
    echo "postBackup called" >/dev/null
}

# preRestore function
preRestore()
{
    # Stop checkpki service to avoid regenerating stunnel.conf during restore
    /etc/init.d/checkpki stop 2> /dev/null
}

# postRestore function
postRestore()
{
    $ROOTACT/lrr/com/sysconfiglrr.sh --restore

    params="$ROOTACT/usr/etc/lrr/_parameters.sh"
    [ -f "$params" ] && . "$params"

    service="$SERVICELRR"
    [ -z "$service" ] && service="/etc/init.d/lrr"
    "$service" stop

    # it fails to stop because pid file is incorrect after restore
    lrrpids=$(pidof -x lrr.x)
    [ ! -z "$lrrpids" ] && kill -TERM $lrrpids
    lrrpids=$(pidof -x lrr)
    [ ! -z "$lrrpids" ] && kill -TERM $lrrpids

    sleep 10

    "$service" start

}
