Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
KERNEL=="sd*", ATTR{size}=="312576642", ATTRS{serial}=="575845343038443733323232", SYMLINK+="backup-drive", RUN+="/root/scripts/backup-trigger"

 

Copy Create the trigger file: /root/scripts/backup-trigger

...

Code Block
#!/bin/bash
 
#logger "Test approved ;)"
 
# all variables
RUNNING="/tmp/offsite-running"
DEVICEPATH="/dev/backup-drive"
MOUNTPOINT="/mnt/offsite-storage"
MAIL="bluelight@auroville.org.in"
LOGFILE=`tempfile -p offsite`
DATE=`date --iso`
ERROR=0
 
logger "offsite backup is running"
# check that the device path is there
if [ ! -h $DEVICEPATH ]; then
echo "devicepath $DEVICEPATH does not exist" >> $LOGFILE
ERROR=1
fi
 
# check that the mountpoint is there
if [ ! -d $MOUNTPOINT ]; then
echo "mount point $MOUNTPOINT does not exist" >> $LOGFILE
ERROR=1
fi
 
## check that the backupdir is there
#if [ ! -d $BACKUPDIR1 ]; then
#echo "backupdir $BACKUPDIR1 does not exist" >> $LOGFILE
#ERROR=1
#fi
#
 
#sleep 5
 
# try to mount
if [ $ERROR -eq 0 ]; then
mount $DEVICEPATH $MOUNTPOINT >> $LOGFILE
fi
 
if [ $? -ne 0 ]; then
echo "mount not successful please check the drive with fsck.jfs $DEVICEPATH" >> $LOGFILE
ERROR=1
fi
 
# run the sync
if [ $ERROR -eq 0 ]; then
sbackup >> $LOGFILE 2>&1
fi
 
# append the actual storage usage to the mail
if [ $ERROR -eq 0 ]; then
df -h $MOUNTPOINT >> $LOGFILE
fi
 
# unmount the drive
umount $DEVICEPATH
if [ $? -ne 0 ]; then
echo "unmounting $DEVICEPATH did not work"
fi
 
# send a mail
cat $LOGFILE | mailx -s "Offsite L'Avenir rsync from $DATE" $MAIL
#cat $LOGFILE | logger
# just in case the script runs through and udev starts is again...
 
sleep 20
 
# cleanup the backup files
#rm $RSYNCLOG
rm $RUNNING
rm $LOGFILE
 
if [ $ERROR -ne 0 ]; then
exit 2
fi
 
logger "Backup completed"
 
exit 0

 

Plug the device and check if it works Smile