Good Day, missing something and could be a dumb question, but....
dlandon created a great script at the beginning of this thread to copy files from unraid to external drive or external drive to unraid. Unfortunately in the portion of the script that uses the $OWNER variable, I don't understand how it works. Its not a command in the linux bash environment and somehow it tests to true when my drive is mounted.
I was under the understanding if I was to unmount or mount the drive myself in the unassigned devices GUI the script is not supposed to execute per dlandon's comment
"If you mount and unmount the drive from the Unassigned Devices gui, the drive will mount and unmount but the script will not run because it has detected the 'OWNER' as 'user' and will skip the backup."
In the script variable "OWNER" is defined in the script to function as -----> : "udev" if executed by UDEV, otherwise "user"
In the script the line comes up to test if the unassigned GUI mount/unmount button is pressed by the user or system
if [ $OWNER = "udev" ]
then
logger command here and
We start the Rsync command here
As $OWNER is a variable (cant find anything in bash environment for OWNER), how is it defined to get the information to test? It seems to test true as the script starts the Rsync command ( condition test ----> [ $OWNER = "udev" ] ) must return 0 to be true, so how it works I'm not sure.
Also the script does run if I press the mount/unmount in the GUI post script copy completion, which is not supposed to happen, so I must be missing a definition for OWNER variable.
My script:
************************************
#!/bin/bash
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
## Available variables:
# AVAIL : available space
# USED : used space
# SIZE : partition size
# SERIAL : disk serial number
# ACTION : if mounting, ADD; if unmounting, UNMOUNT; if unmounted, REMOVE; if error, ERROR_MOUNT, ERROR_UNMOUNT
# FSTYPE : partition filesystem
# LABEL : partition label
# DEVICE : partition device, e.g /dev/sda1
# OWNER : "udev" if executed by UDEV, otherwise "user"
# LOGFILE : log file for this script
MOUNTPOINT=/mnt/disks/PRORAID-BACKUP/Backup/Array
PROG_NAME="Pro-Raid Backup"
case $ACTION in
'ADD' )
#
# Notify that the device is plugged in.
#
echo "External Drive Plugged in: `date`" > $LOGFILE
/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Server Backup" -d "Pro-Raid Backup Mounted" -i "normal"
sleep 2
if [ -d $MOUNTPOINT ]
then
if [ $OWNER = "udev" ]
then
logger -t "$PROG_NAME" Started
echo "Pro-Raid Backup Started: `date`" > $LOGFILE
rsync -av --dry run --stats --delete /mnt/user $MOUNTPOINT/ 2>&1 >> $LOGFILE
logger -t "$PROG_NAME" Syncing
sync -f $MOUNTPOINT
logger -t "$PROG_NAME" Unmounting
/usr/local/sbin/rc.unassigned umount $DEVICE
echo "Pro-Raid Backup Completed: `date`" >> $LOGFILE
logger -t "$PROG_NAME" Drive Can Be Removed
/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Server Backup" -d "Pro-Raid Backup Completed" -i "normal"
fi
else
logger -t "$PROG_NAME" Not Mounted
fi
;;
'REMOVE' )
#
# Indicate that the device is unmounted.
#
/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Server Backup" -d "Pro-Raid Backup Drive Unmounted" -i "normal"
;;
'ERROR_MOUNT' )
/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Server Backup" -d "Could not mount ProRaid Backup" -i "normal"
;;
'ERROR_UNMOUNT' )
/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Server Backup" -d "Could not unmount Pro-Raid Backup" -i "normal"
;;
esac
*********************************
Thanks.