Following script iterates over the array entries, which contains the shares that needs to be backuped:
#!/bin/bash
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
## Available variables:
# ACTION - if mounting, ADD; if unmounting, UNMOUNT; if unmounted, REMOVE; if error, ERROR_MOUNT, ERROR_UNMOUNT
# DEVICE - partition device, e.g. /dev/sda1
# UD_DEVICE - unassigned devX designation
# SERIAL - disk serial number
# LABEL - partition label
# LUKS - if the device is encrypted, this is the partition device, e.g. /dev/sda1
# FSTYPE - partition filesystem
# MOUNTPOINT - where the partition is mounted
# OWNER - "udev" if executed by UDEV, otherwise "user"
# PROG_NAME - program name of this script
# LOGFILE - log file for this script
directorys=( "/mnt/user/folder1"
"/mnt/user/folder2"
"/mnt/user/folder3"
"/boot/config/plugins/unassigned.devices")
notify_event="<Name of NAS>"
notify_subject="backup ext. disk"
notify_message="Follwoing shares were synced:"$'\n'
case $ACTION in
'ADD' )
#
# Beep that the device is plugged in.
#
beep -l 200 -f 600 -n -l 200 -f 800
sleep 2
if mountpoint -q $MOUNTPOINT; then
if [ $OWNER = "udev" ]
then
beep -l 100 -f 2000 -n -l 150 -f 3000
beep -l 100 -f 2000 -n -l 150 -f 3000
logger Started -t $PROG_NAME
echo "Started: `date`" > $LOGFILE
for dir in "${directorys[@]}";
do
echo "#### Start: [`date`] ####" >> $LOGFILE
echo "# sync of share: ${dir} #" >> $LOGFILE
rsync -a -v "$dir" $MOUNTPOINT/ 2>&1 >> $LOGFILE
echo "## End: [`date`] ##" >> $LOGFILE
notify_message+="$dir"$'\n'
done
logger Syncing -t$PROG_NAME
sync -f $MOUNTPOINT
beep -l 100 -f 2000 -n -l 150 -f 3000
beep -l 100 -f 2000 -n -l 150 -f 3000
beep -r 5 -l 100 -f 2000
logger Unmounting Ext. HDDBackup Backup -t $PROG_NAME
/usr/local/sbin/rc.unassigned umount $DEVICE
echo "Completed: `date`" >> $LOGFILE
logger Backup drive can be removed -t$PROG_NAME
/usr/local/emhttp/webGui/scripts/notify -e "$notify_event" -s "$notify_subject" -d "Backup completed" -i "alert" -m "$notify_message"
fi
else
logger Backup drive not mounted -t$PROG_NAME
fi
;;
'REMOVE' )
#
# Beep that the device is unmounted.
#
beep -l 200 -f 800 -n -l 200 -f 600
;;
'ERROR_MOUNT' )
/usr/local/emhttp/webGui/scripts/notify -e "$notify_event" -s "$notify_subject" -d "Could not mount disk!" -i "alert"
;;
'ERROR_UNMOUNT' )
/usr/local/emhttp/webGui/scripts/notify -e "$notify_event" -s "$notify_subject" -d "Could not unmount disk!" -i "alert"
;;
The mail notifcation works via "alert"-state for the notification method -> 'ERROR_MOUNT'/'ERROR_UNMOUNT' -> In the system settings of the NAS, under the notification conriguration, I configuered that system notification with alert state will send as mail to.