Add NFS mount and backup
This commit is contained in:
44
backup.sh
44
backup.sh
@@ -10,11 +10,33 @@ STORAGE_MOUNT_POINT="/media/storage"
|
|||||||
CARD_DEV="sdb1"
|
CARD_DEV="sdb1"
|
||||||
CARD_MOUNT_POINT="/media/card"
|
CARD_MOUNT_POINT="/media/card"
|
||||||
|
|
||||||
|
# If there is a wpa_supplicant.conf file in the root of the storage device
|
||||||
|
# Rename the original config file,
|
||||||
|
# move wpa_supplicant.conf from the card to /etc/wpa_supplicant/
|
||||||
|
# Reboot to enable networking
|
||||||
|
if [ -f "$STORAGE_MOUNT_POINT/wpa_supplicant.conf" ]; then
|
||||||
|
sudo sh -c "echo 100 > /sys/class/leds/led0/delay_on"
|
||||||
|
mv /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bak
|
||||||
|
mv "$STORAGE_MOUNT_POINT/wpa_supplicant.conf" /etc/wpa_supplicant/wpa_supplicant.conf
|
||||||
|
reboot
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If there is a nfs_mount file in the root of the storage device
|
||||||
|
# Read the mount command and mount an NFS export
|
||||||
|
if [ -f "$STORAGE_MOUNT_POINT/nfs_mount" ]; then
|
||||||
|
sudo sh -c "echo 100 > /sys/class/leds/led0/delay_on"
|
||||||
|
NFS_COMMAND=$(head -n 1 "$STORAGE_MOUNT_POINT/nfs_mount")
|
||||||
|
sudo $NFS_COMMAND
|
||||||
|
NFS_MOUNT_POINT=`echo "$NFS_COMMAND" cut -d" " -f5`
|
||||||
|
else
|
||||||
|
NFS_MOUNT_POINT=""
|
||||||
|
fi
|
||||||
|
|
||||||
# Set the ACT LED to heartbeat
|
# Set the ACT LED to heartbeat
|
||||||
sudo sh -c "echo heartbeat > /sys/class/leds/led0/trigger"
|
sudo sh -c "echo heartbeat > /sys/class/leds/led0/trigger"
|
||||||
|
|
||||||
# Shutdown after 7 minutes if no device is connected.
|
# Shutdown after 5 minutes if no device is connected.
|
||||||
sudo shutdown -h 7 "Shutdown is activated. To cancel: sudo shutdown -c"
|
sudo shutdown -h 5 "Shutdown is activated. To cancel: sudo shutdown -c"
|
||||||
|
|
||||||
# Wait for a USB storage device (e.g., a USB flash drive)
|
# Wait for a USB storage device (e.g., a USB flash drive)
|
||||||
STORAGE=$(ls /dev/* | grep $STORAGE_DEV | cut -d"/" -f3)
|
STORAGE=$(ls /dev/* | grep $STORAGE_DEV | cut -d"/" -f3)
|
||||||
@@ -34,17 +56,6 @@ sudo shutdown -c
|
|||||||
sudo sh -c "echo timer > /sys/class/leds/led0/trigger"
|
sudo sh -c "echo timer > /sys/class/leds/led0/trigger"
|
||||||
sudo sh -c "echo 1000 > /sys/class/leds/led0/delay_on"
|
sudo sh -c "echo 1000 > /sys/class/leds/led0/delay_on"
|
||||||
|
|
||||||
# If there is a wpa_supplicant.conf file in the root of the storage device
|
|
||||||
# Rename the original config file,
|
|
||||||
# move wpa_supplicant.conf from the card to /etc/wpa_supplicant/
|
|
||||||
# Reboot to enable networking
|
|
||||||
if [ -f "$STORAGE_MOUNT_POINT/wpa_supplicant.conf" ]; then
|
|
||||||
sudo sh -c "echo 100 > /sys/class/leds/led0/delay_on"
|
|
||||||
mv /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bak
|
|
||||||
mv "$STORAGE_MOUNT_POINT/wpa_supplicant.conf" /etc/wpa_supplicant/wpa_supplicant.conf
|
|
||||||
reboot
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Wait for a card reader or a camera
|
# Wait for a card reader or a camera
|
||||||
CARD_READER=$(ls /dev/* | grep $CARD_DEV | cut -d"/" -f3)
|
CARD_READER=$(ls /dev/* | grep $CARD_DEV | cut -d"/" -f3)
|
||||||
until [ ! -z $CARD_READER ]
|
until [ ! -z $CARD_READER ]
|
||||||
@@ -75,6 +86,13 @@ sudo lsblk > lsblk.log
|
|||||||
|
|
||||||
# Perform backup using rsync
|
# Perform backup using rsync
|
||||||
rsync -av --exclude "*.id" $CARD_MOUNT_POINT/ $BACKUP_PATH
|
rsync -av --exclude "*.id" $CARD_MOUNT_POINT/ $BACKUP_PATH
|
||||||
|
|
||||||
|
# If an NFS export is mounted
|
||||||
|
# Back up files to it
|
||||||
|
if [ ! -z "$NFS_MOUNT_POINT" ]; then
|
||||||
|
rsync -av --exclude "*.id" $BACKUP_PATH/ $NFS_MOUNT_POINT
|
||||||
|
fi
|
||||||
|
|
||||||
# Turn off the ACT LED to indicate that the backup is completed
|
# Turn off the ACT LED to indicate that the backup is completed
|
||||||
sudo sh -c "echo 0 > /sys/class/leds/led0/brightness"
|
sudo sh -c "echo 0 > /sys/class/leds/led0/brightness"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user