Originally Posted by
TheFu
It can be run at reboot or at specific times or you could setup your script to recognize when the USB disk is connected+mounted and only then run the backups.
The USB being connected doesn't have to mean it is mounted.
Thats interesting, as I already have functionality in my backup script to recognise if the USB HDD is connected (see code below).
However, that would mean the backup would only happen when crontab calls the backup script, which would be at a certain date and time.
So to perform the backup, I would need to connect the USB HDD BEFORE the crontab calls the backup script ?
e.g. if I configured crontab to run the backup script daily at 5pm, I would need to connect the USB HDD BEFORE 5pm (or leave it connected and wait until the next day at 5pm).
I don't suppose the crontab can detect when the USB HDD is connected and then run the script ?
Code:
if [ -z $1 ] ; then
echo "Parameter missing: define -onsite, -offsite.loc or -offsite.rem"
exit
elif [ "-onsite" = $1 ] ; then
# check external USB HDD is connected
if ! mount | grep -q /media/backupstorage; then
echo "Onsite HDD not mounted"
exit
else
echo "+++++++++++++++++++++ Performing onsite backup +++++++++++++++++++++"
fi
elif [ "-offsite.loc" = $1 ] ; then
# check external USB HDD is connected
if ! mount | grep -q /media/storageBackupOS; then
echo "Offsite HDD not mounted locally"
exit
else
echo "+++++++++++++++++++++ Performing local offsite backup +++++++++++++++++++++"
fi
elif [ "-offsite.rem" = $1 ] ; then
# check external USB HDD is connected
if ! mount | grep -q /Volumes/storageBackupOS; then
echo "Offsite HDD not mounted remotely"
exit
else
echo "+++++++++++++++++++++ Performing remote offsite backup +++++++++++++++++++++"
fi
else
echo "$1 invalid: define -onsite, -offsite.loc or -offsite.rem"
exit
fi