#!/bin/bash
mkdir -p /opt/hotfixer/backups

backupfiles_length=$(jq '.backup_files | length' /$1.conf)

timestamp=$(date +%s)
backupName="/opt/hotfixer/backups/$1_$timestamp.tar.gz"
temDirectory="/$1"
mkdir -p $temDirectory

files=""

for (( c=0; c<=$backupfiles_length - 1; c++ ))
do
   file=$(jq .backup_files[$c] /$1.conf | tr -d '"')
   files="$files $file"
   cp  $file $temDirectory
done

if [[ $files != "" ]]; then
  tar -czvf $backupName $temDirectory
  echo "Back-up finish !"
else
    echo "Nothing to back-up"
fi

rm -rf $temDirectory
