41 lines
822 B
Bash
Executable file
41 lines
822 B
Bash
Executable file
#!/bin/bash
|
|
|
|
FILE=/var/run/bkp-usb-detected
|
|
|
|
|
|
function usage () {
|
|
[ -n "$1" ] && echo -e "$1\n"
|
|
echo "Usage : $0 [device]"
|
|
echo " device To manually run export, provide the USB Drive device path"
|
|
[ -n "$1" ] && exit 1
|
|
return 0
|
|
}
|
|
|
|
function exit_error () {
|
|
[ -n "$1" ] && echo "$1"
|
|
beep -f 300 -l 2000
|
|
rm -f "$FILE"
|
|
exit 1
|
|
}
|
|
|
|
# Manually run
|
|
if [ -n "$1" ]
|
|
then
|
|
[ "$1" == "-h" ] && usage && exit 0
|
|
DEVICE="$1"
|
|
[ ! -b "$DEVICE" ] && usage "Invalid device '$DEVICE'"
|
|
echo -n "$DEVICE" > $FILE
|
|
exit 0
|
|
fi
|
|
|
|
[ ! -e "$FILE" ] && exit_error "File $FILE does not exists !"
|
|
|
|
DEVICE=$( cat "$FILE" )
|
|
[ ! -e "$DEVICE" ] && exit_error "Device '$DEVICE' does not exists !"
|
|
|
|
echo "Removing $FILE"
|
|
rm -f "$FILE"
|
|
|
|
echo "Run backup on device '$DEVICE'"
|
|
/usr/local/sbin/backup-usb -u "$DEVICE" -l /var/log/bkp-usb.log &
|
|
exit 0
|