#!/bin/bash
backup_dir="/home/backup"
if [ "256T" != "$(df -h|grep $backup_dir|awk '{print $2}')" ]; then
  logger "Backup error: $backup_dir is not mounted to S3 storage!"
  exit 1
fi
cd $backup_dir
printf "*** Full system backup ***\tstarted\t\t`date`\n">>log
if [ ! -d old ]; then
  mkdir old
fi
# remove files older that 13 days
find ./old -name 'system_full*' -mtime +13 -exec rm '{}' \;

if [ -r system_full.1.dar ]; then
  mv system_full* old
fi

nice -n20 \
dar -Q -c $backup_dir/system_full -w -asecu -aSI -s 2G -D -R / \
  -z -Z "*.tgz" -Z "*.gz" -Z "*.bz2" -Z "*.zip" -Z "*.png" \
  -P home -P tmp -P mnt -P media -P dev/pts -P sys -P proc \
  -P "swapfile*" -P var/lib/lxcfs \
  >>err_log 2>&1
echo `date`>>err_log
printf "\t\t\t\t finished\t`date`\n">>log
exit 0
