#!/bin/bash
#
# Sync the media from our shared NFS directory to our local backup copy.
# 
# Two issues this solves: 
#       - Only sync if the NFS mount is operational (so as to not wipe out the backups)
#       - Ensure that the local copy is read-only for apache so that file-uploads won't
#         succeed in read-only mode.
#

SHARED=/mnt/files/
BACKUP=/srv/file_read_only/
TO="webmaster@example.edu"

if [ -f ${SHARED}/online ]
then
        rsync -r --perms=false --exclude=online --delete $SHARED $BACKUP
else
        SUBJECT="Drupal NFS Status"
        mail -s "$SUBJECT" $TO <<EOF
Alert from `hostname`:
The Drupal image directory at $SHARED is not available.

Image syncronization skipped.

Time: `date`
EOF
fi

