Backups using rsync

[LEFT]Hello all,

I'm using nas4free as a SAN and am having troubles getting a backup of it's data to work properly. I've posted in the nas4free forums, but haven't received much help.

Here is the code I'm using:

#!/bin/sh
{
#########################################################################################
# File:    casedatabackup.sh
# Author:    Daryl Patino
# Date:   03-18-2013
# Purpose:   Daily incremental backups and weekly archive of backups using rsync
#
# 
# Important Usage Notes:
# -cp this file with a different name to retain this file as a template
# -edit logfilename located in BODY variable and end of script to match share
# -view existing scripts for examples
# -end all directory variables with /
# -must run the following command on the file "chmod u+x /path/file"
#########################################################################################


#########################################################################################
# Constant variables, do not change
#########################################################################################

DAY=$(date +%A)
DATE=$(date +%m_%d_%y)
PRINTF=/usr/bin/printf
MSMTP=/usr/local/bin/msmtp
MSMTPCONF=/var/etc/msmtp.conf


#########################################################################################
# Dynamic variables, changeable
#########################################################################################

# Mail settings
FROM="nas4free@usinfosec.com"
TO="helpdesk@usinfosec.com"
MDIR="CaseData"
SUBJECT="$MDIR Backup Report"
BODY="$(cat /mnt/support/logs/casedata.log)"

# Sync settings
RSOURCE="/mnt/POOL/CaseData/"
RDEST="/mnt/syl-s-012/Backups/CaseData/Daily/"
ASOURCE=$RDEST
ADEST="/mnt/syl-s-012/Backups/CaseData/Weekly/"


#########################################################################################
# Backup operations
#########################################################################################

# Daily file sync
rsync -a --stats $RSOURCE $RDEST

# Weekly archive and follow up sync to remove deleted files
if [ $day = "Sunday" ]; then
   tar -zcf $ADEST$DATE.tar.gz $ASOURCE
   rsync -a --delete --stats $RSOURCE $RDEST
   find $ADEST -mtime +14 -exec rm {} \;
fi

# Sends email of log file
$PRINTF "From:$FROM\nTo:$TO\nSubject:$SUBJECT\n\n$BODY" | $MSMTP --file=$MSMTPCONF -t

} > /mnt/support/logs/casedata.log

It is scheduled to run as a cron once per day via the nas4free gui. The script runs, and the daily rsync works, but the log file is empty and the weekly commands (in the if statement) do not seem to be working. When I run the tar individually, I get the following:

I know that the embedded nas4free doesn't have room to install any additional applications, but the source and destination are mounted shares.

So my questions are this.

Does tar use some kind of temp directory that is local? If so, can it be changed?

My logging syntax might be incorrect. If so, how can I create a log of the scripts output that can be emailed?
[/LEFT]

If I am going to delete stuff after archiving it into a tar (and I prefer a zip so you have random access to every file, and compression tailored to every file), youshould have marker times or files with times so the only files you remove are unchanged since a second before the tar/zip. Also, I like to get the names out of a tar (or unzip) listing, in case there is a problem with the tar (or zip) file, like running out of space or being signalled. Also, check $? one way or another so you do not proceed when things went awry!

There are tools like jdbc from hxtt that can SQL query wild card lists of files in trees, including zip files as if dirs and their internal trees in mid-tree, so the archived data is still a peer to raw files.