#!/bin/sh
# Creates home/ backup and moves it to $move_to

# gets current date
cur_date=$(date +%d_%m_%Y|sed -e 's/^ *//');
# prefix name for the backup
backup_name_prefix='fresh-ringtones-home_backup';
# directory to archive with tar 
dir_to_backup='home/';
# directory to move to after archive is created
move_to='/backups/server4-207_234_147_191/site-backups/';
# error log location
err_log='/var/log/home_backup.log';
# name of the full created archive (do not edit)
b_archive_name="${backup_name_prefix}_${cur_date}.tar.gz";

cr_backup () {
if [[ -d / ]]; then
cd /
/bin/nice -n 12 /bin/tar -czvf $b_archive_name \
${dir_to_backup} --exclude='customusers/default/b-usage/*' --exclude='customusers/backups1/*' >/dev/null 2>&1;
fi
}

do_stuff_with_backup () {
if [[ -s /${b_archive_name} ]]; then
/bin/mv /${b_archive_name} ${move_to};
else
echo "Something wicked happened while trying to move ${b_archive_name}">>${err_log};
exit 1;
fi
}
main () {
cr_backup;
do_stuff_with_backup;
}
main;

