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
This commit is contained in:
Dmitri Popov
2018-03-22 13:32:34 +01:00
parent 33d0ce8627
commit 8285ef5f40
6 changed files with 77 additions and 14 deletions

View File

@@ -34,9 +34,9 @@ BACKTITLE="Little Backup Box"
TITLE="Backup mode" TITLE="Backup mode"
MENU="Select the desired backup mode:" MENU="Select the desired backup mode:"
OPTIONS=(1 "Card backup" OPTIONS=(1 "Remote control"
2 "Camera backup" 2 "Card backup"
3 "Remote backup") 3 "Camera backup")
CHOICE=$(dialog --clear \ CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \ --backtitle "$BACKTITLE" \
@@ -49,19 +49,19 @@ CHOICE=$(dialog --clear \
clear clear
case $CHOICE in case $CHOICE in
1) 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/scripts/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/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/rc/rc.py"; } | crontab
;; ;;
2) 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/scripts/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/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/rc/rc.py"; } | crontab
;; ;;
3) 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/scripts/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/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/rc/rc.py"; } | crontab
;; ;;
esac esac

View File

@@ -23,9 +23,11 @@ def remote_control():
st = os.statvfs("/home/dmpop") st = os.statvfs("/home/dmpop")
free = "%.2f" % float((st.f_bavail * st.f_frsize)/1.073741824e9) free = "%.2f" % float((st.f_bavail * st.f_frsize)/1.073741824e9)
if (request.POST.get("cardbackup")): 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")): 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")): if (request.POST.get("shutdown")):
os.system("sudo shutdown -h now") os.system("sudo shutdown -h now")
return template('rc.tpl', freespace=free) return template('rc.tpl', freespace=free)

View File

@@ -42,8 +42,10 @@
<p class="center">Free disk space: <b>{{freespace}}</b> GB</p> <p class="center">Free disk space: <b>{{freespace}}</b> GB</p>
<p><input id="btn" name="cardbackup" type="submit" value="Card backup"></p> <p><input id="btn" name="cardbackup" type="submit" value="Card backup"></p>
<p class="left">Back up a storage card connected via a card reader</p> <p class="left">Back up a storage card connected via a card reader</p>
<p><input id="btn" class="orange" name="camerabackup" type="submit" value="Camera backup"></p> <p><input id="btn" name="camerabackup" type="submit" value="Camera backup"></p>
<p class="left">Transfer files directly from the connected camera</p> <p class="left">Transfer files directly from the connected camera</p>
<p><input id="btn" class="orange" name="devicebackup" type="submit" value="Internal backup"></p>
<p class="left">Back up files from the internal storage to an external storage device</p>
<p><input id="btn" class="red" name="shutdown" value="Shut down" type="submit" /></p> <p><input id="btn" class="red" name="shutdown" value="Shut down" type="submit" /></p>
<p class="left">Shut down the Little Backup Box</p> <p class="left">Shut down the Little Backup Box</p>
</div> </div>

59
scripts/device-backup.sh Executable file
View File

@@ -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 <http://www.gnu.org/licenses/>.
# 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