#!/bin/sha
time=$(date +”%m_%d_%Y”)
user=””
path=””
backuppath=””
report=”$backuppath/report”
rm -r $report
echo $time >> $backuppath/report
#tar.gz to /mnt
tar -zcvf $backuppath/$user/”$user”_”$time”.tar.gz -C $path/$user . >> $report
#check how many backups in folder
countbackups=$( ls $backuppath/$user | wc -l ) >> $report
if [ $countbackups -ge 2 ];
then
#Get the oldest backup
getOldest=$( ls -lat $backuppath/$user | awk ‘{ print $9 }’ | grep tar.gz | tail -1 )
echo “removing oldest backup $getOldest” >> $report
#Remove the oldest backup
rmOldest=$( rm $backuppath/$user/$getOldest )
fi