#!/bin/bash
#
# This script will backup LauraGB's /home/gberardi to the 
# larger hard drive at /mnt/Backup/LauraGB/Debian/home/gberardi weekly.
# Each week a different directory is used to avoid losing data from 
# one week to the next
#
# It will also backup to a second larger drive monthly on MariaGB

BACKUP_DIR_ROOT=/mnt/Backup/LauraGB/Debian/home/gberardi

#theDate will hold the numerical value of the date (1-31)
theDate=`date +%e`
BACKUPDIR=$BACKUP_DIR_ROOT/week$((theDate/7+1))
MONTHLY="y"


if [ $theDate -le "7" ]
     then
	 # since it is week1, make the monthly copy to Maria
	 MONTHLY=y
fi

# remove old weekX backup directory
echo "Removing old backup at $BACKUPDIR..."
rm -rf $BACKUPDIR/*
echo "Backing up to $BACKUPDIR..."
# copy /home/gberardi to weekX
rsync -e ssh -azvP /home/gberardi $BACKUPDIR/


# check if monthly backup should be made
if [ $MONTHLY == "y" ]
	then
	echo
	echo "Making monthly backup..."
	tar -cvvjf $BACKUP_DIR_ROOT/monthly/LauraGBHomeBackup-$(date +%F).tar.bz2 $BACKUPDIR
	# presumably when Maria is ready, scp the tar.gz file
	# NOTE: needs trusted access to automate it
	# scp -p $BACKUP_DIR_ROOT/monthly/LauraGBHomeBackup-$(date +%F).tar.bz2
	# MariaGB:/some/directory/over/here/
fi


