aboutsummaryrefslogtreecommitdiff
path: root/script/usb.sh
diff options
context:
space:
mode:
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