aboutsummaryrefslogtreecommitdiff
path: root/script/usb.sh
diff options
context:
space:
mode:
authorAndreas Lindhé <andreas@lindhe.io>2018-04-06 11:13:29 +0200
committerAndreas Lindhé <andreas@lindhe.io>2018-04-06 11:13:29 +0200
commit2842bb1f114fbecdd953e33e536fc112be2f4dc0 (patch)
tree0f26946a35e398f8426adf0fb0bc883e453ab504 /script/usb.sh
parentf406a5d8409062ad296eb696332659a70e87a4f7 (diff)
downloadmidbro-2842bb1f114fbecdd953e33e536fc112be2f4dc0.tar.gz
midbro-2842bb1f114fbecdd953e33e536fc112be2f4dc0.tar.bz2
Add the logging and USB mount/umount scripts
Diffstat (limited to 'script/usb.sh')
-rwxr-xr-xscript/usb.sh46
1 files changed, 46 insertions, 0 deletions
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