From 2842bb1f114fbecdd953e33e536fc112be2f4dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Lindh=C3=A9?= Date: Fri, 6 Apr 2018 11:13:29 +0200 Subject: Add the logging and USB mount/umount scripts --- script/usb.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 script/usb.sh (limited to 'script/usb.sh') diff --git a/script/usb.sh b/script/usb.sh new file mode 100755 index 0000000..73c946c --- /dev/null +++ b/script/usb.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +#Function to check if the time is during working hours +function workingHours() +{ + now=$(date +%H:%M) + if [[ "$now" < "15:00" ]] && [[ "$now" > "13:00" ]]; then + return 0; + else + return 1; + fi +} + +# Mount locations +primary="/mnt/primary" +backup="/mnt/backup" + +# Create directories +if ! [ -d "$primary" ]; then + mkdir -p "$primary" +fi + +if ! [ -d "$backup" ]; then + mkdir -p "$backup" +fi + +# If primary is not mounted, mount it +if ! mount | grep $primary > /dev/null 2>&1; then + mount LABEL=PRIMARY "$primary" > /dev/null 2>&1 +fi + +# If primary is mounted, sync +if mount | grep $primary > /dev/null 2>&1; then + rsync -rltDqzPcO --no-perms --backup-dir=old /home/pi/data "$primary" +fi + +# If is not working hours and backup is not mounted, mount it +if ! workingHours && ! mount | grep $backup > /dev/null 2>&1; then + mount LABEL=BACKUP "$backup" > /dev/null 2>&1 +fi + +# If the backup is mounted, sync +if mount | grep $backup > /dev/null 2>&1; then + rsync -rltDqzPcO --no-perms --backup-dir=old /home/pi/data "$backup" + umount LABEL=BACKUP "$backup" > /dev/null 2>&1 +fi -- cgit v1.2.1