From 8285ef5f40a4f83d8a0ff2f255b7cbd5da2e69e9 Mon Sep 17 00:00:00 2001 From: Dmitri Popov Date: Thu, 22 Mar 2018 13:32:34 +0100 Subject: [PATCH] Add device backup modified: ../install-little-backup-box.sh modified: rc.py modified: rc.tpl renamed: ../camera-backup.sh -> ../scripts/camera-backup.sh renamed: ../card-backup.sh -> ../scripts/card-backup.sh new file: ../scripts/device-backup.sh --- install-little-backup-box.sh | 22 ++++---- rc/rc.py | 6 +- rc/rc.tpl | 4 +- camera-backup.sh => scripts/camera-backup.sh | 0 card-backup.sh => scripts/card-backup.sh | 0 scripts/device-backup.sh | 59 ++++++++++++++++++++ 6 files changed, 77 insertions(+), 14 deletions(-) rename camera-backup.sh => scripts/camera-backup.sh (100%) rename card-backup.sh => scripts/card-backup.sh (100%) create mode 100755 scripts/device-backup.sh diff --git a/install-little-backup-box.sh b/install-little-backup-box.sh index 1350fcf..3d47b8b 100755 --- a/install-little-backup-box.sh +++ b/install-little-backup-box.sh @@ -34,9 +34,9 @@ BACKTITLE="Little Backup Box" TITLE="Backup mode" MENU="Select the desired backup mode:" -OPTIONS=(1 "Card backup" - 2 "Camera backup" - 3 "Remote backup") +OPTIONS=(1 "Remote control" + 2 "Card backup" + 3 "Camera backup") CHOICE=$(dialog --clear \ --backtitle "$BACKTITLE" \ @@ -49,19 +49,19 @@ CHOICE=$(dialog --clear \ clear case $CHOICE in 1) - crontab -l | { cat; echo "@reboot sudo /home/pi/little-backup-box/card-backup.sh"; } | crontab - crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/camera-backup.sh"; } | crontab - crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/rc/rc.py"; } | crontab + crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/scripts/card-backup.sh"; } | crontab + crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/scripts/camera-backup.sh"; } | crontab + crontab -l | { cat; echo "@reboot sudo /home/pi/little-backup-box/rc/rc.py"; } | crontab ;; 2) - crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/card-backup.sh"; } | crontab - crontab -l | { cat; echo "@reboot sudo /home/pi/little-backup-box/camera-backup.sh"; } | crontab + crontab -l | { cat; echo "@reboot sudo /home/pi/little-backup-box/scripts/card-backup.sh"; } | crontab + crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/scripts/camera-backup.sh"; } | crontab crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/rc/rc.py"; } | crontab ;; 3) - crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/card-backup.sh"; } | crontab - crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/camera-backup.sh"; } | crontab - crontab -l | { cat; echo "@reboot sudo /home/pi/little-backup-box/rc/rc.py"; } | crontab + crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/scripts/card-backup.sh"; } | crontab + crontab -l | { cat; echo "@reboot sudo /home/pi/little-backup-box/scripts/camera-backup.sh"; } | crontab + crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/rc/rc.py"; } | crontab ;; esac diff --git a/rc/rc.py b/rc/rc.py index 245906a..0aa77e6 100755 --- a/rc/rc.py +++ b/rc/rc.py @@ -23,9 +23,11 @@ def remote_control(): st = os.statvfs("/home/dmpop") free = "%.2f" % float((st.f_bavail * st.f_frsize)/1.073741824e9) if (request.POST.get("cardbackup")): - os.system("sudo /home/pi/little-backup-box/card-backup.sh") + os.system("sudo /home/pi/little-backup-box/scripts/card-backup.sh") if (request.POST.get("camerabackup")): - os.system("sudo /home/pi/little-backup-box/camera-backup.sh") + os.system("sudo /home/pi/little-backup-box/scripts/camera-backup.sh") + if (request.POST.get("internalbackup")): + os.system("sudo /home/pi/little-backup-box/scripts/device-backup.sh") if (request.POST.get("shutdown")): os.system("sudo shutdown -h now") return template('rc.tpl', freespace=free) diff --git a/rc/rc.tpl b/rc/rc.tpl index 475d228..6fc29e3 100644 --- a/rc/rc.tpl +++ b/rc/rc.tpl @@ -42,8 +42,10 @@

Free disk space: {{freespace}} GB

Back up a storage card connected via a card reader

-

+

Transfer files directly from the connected camera

+

+

Back up files from the internal storage to an external storage device

Shut down the Little Backup Box

diff --git a/camera-backup.sh b/scripts/camera-backup.sh similarity index 100% rename from camera-backup.sh rename to scripts/camera-backup.sh diff --git a/card-backup.sh b/scripts/card-backup.sh similarity index 100% rename from card-backup.sh rename to scripts/card-backup.sh diff --git a/scripts/device-backup.sh b/scripts/device-backup.sh new file mode 100755 index 0000000..0e49da5 --- /dev/null +++ b/scripts/device-backup.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# IMPORTANT: +# Run the install-little-backup-box.sh script first +# to install the required packages and configure the system. + +# Specify devices and their mount points +# and other settings +STORAGE_DEV="sda1" # Name of the storage device +STORAGE_MOUNT_POINT="/media/storage" # Mount point of the storage device +SOURCE_DIR="/home/pi/BACKUP/" +SHUTD="5" # Minutes to wait before shutdown due to inactivity + +# Set the ACT LED to heartbeat +sudo sh -c "echo heartbeat > /sys/class/leds/led0/trigger" + +# Shutdown after a specified period of time (in minutes) if no device is connected. +sudo shutdown -h $SHUTD "Shutdown is activated. To cancel: sudo shutdown -c" + +# Wait for a USB storage device (e.g., a USB flash drive) +STORAGE=$(ls /dev/* | grep $STORAGE_DEV | cut -d"/" -f3) +while [ -z ${STORAGE} ] + do + sleep 1 + STORAGE=$(ls /dev/* | grep $STORAGE_DEV | cut -d"/" -f3) +done + +# When the USB storage device is detected, mount it +mount /dev/$STORAGE_DEV $STORAGE_MOUNT_POINT + +# Cancel shutdown +sudo shutdown -c + +# Set the ACT LED to blink at 1000ms to indicate that the storage device has been mounted +sudo sh -c "echo timer > /sys/class/leds/led0/trigger" +sudo sh -c "echo 1000 > /sys/class/leds/led0/delay_on" + + # Perform backup using rsync + rsync -av $SOURCE_DIR $STORAGE_MOUNT_POINT + + # Turn off the ACT LED to indicate that the backup is completed + sudo sh -c "echo 0 > /sys/class/leds/led0/brightness" +fi +# Shutdown +sync +shutdown -h now