From b475fd4d77589e4d4df3484fec4555e8d1cbba58 Mon Sep 17 00:00:00 2001 From: Pnumekin <14359314+Pnumekin@users.noreply.github.com> Date: Mon, 4 Sep 2017 19:44:48 +0200 Subject: [PATCH] Update backup.sh In case of making a backup to format the card and shoot new photos/videos, I need to be sure to have a valid backup. I check if there is enough space on storage to make the backup, else shutting down the Pi. User feedback in that case is not perfect, ACT led is turned off, it should exist a better way to warn the user. --- backup.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backup.sh b/backup.sh index ee98f99..e7d52f8 100755 --- a/backup.sh +++ b/backup.sh @@ -61,6 +61,15 @@ if [ ! -z $CARD_READER ]; then # and use it as a directory name in the backup path read -r ID < $CARD_MOUNT_POINT/CARD_ID BACKUP_PATH=$STORAGE_MOUNT_POINT/"$ID" + +# Shutdown if there is not enough free space on storage +STORAGEFREE=$(df -P /dev/sda1 | awk 'NR==2 {print $4}') +TRANSFERTAMOUNT=$(($(rsync -an --stats $CARD_MOUNT_POINT/ $BACKUP_PATH | awk '/Total transferred file size:/ {print $5}' | sed 's/,//g') /1024 )) +if (($STORAGEFREE < $TRANSFERTAMOUNT)); then +sudo sh -c "echo 0 > /sys/class/leds/led0/brightness" +shutdown -h now +fi + # Perform backup using rsync rsync -avh $CARD_MOUNT_POINT/ $BACKUP_PATH # Turn off the ACT LED to indicate that the backup is completed