#!/bin/bash

# Usage:
#   sng-archive-backup <archive type> <archive name>
# Archive type is used to select configuration file as:
#   /etc/<archive type>-backup.conf
CFG=/etc/$1-backup.conf
if [ ! -f $CFG ]; then
  echo 'Backup type $1 configuration file missing.'
  exit -1
fi
# Add backup type and system identity
rm -rf /var/tmp/backup
mkdir -p /var/tmp/backup
echo $1 > /var/tmp/backup/type
/usr/local/sng/bin/sng-system-identity > /var/tmp/backup/identity
# additional files
AUTO_FILES="/var/tmp/backup/*"
# Create file list from configuration file, remove line containing # (comment)
FILES=`cat $CFG | grep -v '#'`

/bin/tar --ignore-failed-read -cpszf  $2 $AUTO_FILES $FILES > /dev/null 2>&1

#ignore tar exit 1 with  'file changed as we read it' error
if [ $? -eq 1 ]; then
  exit 0
fi
