#!/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 home backup   ***\tstarted\t\t`date`\n">>log
if [ ! -d old ]; then
  mkdir old
fi
# remove files older that 58 days
find ./old -name 'home_full*' -mtime +58 -exec rm '{}' \;

if [ -r home_full.1.dar ]; then
  mv home_full* old
fi
nice -n20 \
dar -Q -c $backup_dir/home_full -w -asecu -aSI -s 4G -D -R /home  \
  -z -Z "*.tgz" -Z "*.gz" -Z "*.bz2" -Z "*.zip" -Z "*.png" -Z "*.gif" -Z "*.jpg" -Z "*.mp3" \
  -P backup -P lost+found -P mysql -P s3 \
  -P ftp/tmp/*.mp4 \
  -P oto/valdis/Cloudstore -P swapfile* \
   >>err_log 2>&1
echo `date`>>err_log
printf "\t\t\t\t finished\t`date`\n">>log
exit 0
