#!/bin/sh

# The first directory for backup
old_tarballs=`ls /var/backup/first/first-[0-9]*.tar.gz`
bkdir=/home/student/data

if [ -d  $bkdir ]
then
    # Make a new tarball
    tarball=/var/backup/first/first-`/bin/date +%Y%m%d`.tar.gz
    /bin/tar czf $tarball $bkdir
else
    /usr/bin/logger -p cron.error -t BACKUP "Directory $bkdir not found."
fi

# Copy the new tarball on the keeper
if [ -f $tarball ]
then
    /usr/bin/rsync $tarball c17.class.un::c11
    # Remove oldtarballs
    for oldtarball in $old_tarballs
    do
        /bin/rm $oldtarball
    done
else
    /usr/bin/logger -p cron.error -t BACKUP "Tarball $tarball not found. No backup."
fi

exit 0
