From 47b4c4ee12f7d13f75f9af4d89e305daace14e6e Mon Sep 17 00:00:00 2001 From: Dmitri Popov Date: Tue, 30 Jan 2018 19:25:34 +0100 Subject: [PATCH 1/2] Squashed commit of the following: commit a2c130b657fe99c388d122091c295047b1c39f58 Author: Dmitri Popov Date: Tue Jan 30 19:15:43 2018 +0100 Minor tweak commit 257a3276561fe2a07f1098f1d052818396a81f51 Author: Dmitri Popov Date: Tue Jan 30 19:09:24 2018 +0100 Fix -ext commit b2e5b1ceec712e055004c57faec49261de90adfe Author: Dmitri Popov Date: Tue Jan 30 15:28:24 2018 +0100 Update README.md commit 5e355631562a3cc82a102f0009734a1278d8cd17 Author: Dmitri Popov Date: Tue Jan 30 15:03:04 2018 +0100 Comment options. Shutdown time as variable commit 36386b00d89c525d6d0df760541ed3ed8a73bb6b Author: Dmitri Popov Date: Tue Jan 30 14:58:12 2018 +0100 Add geotagging commit 59390b24eeec239207523d4eda00b9d8ddb2639e Author: Dmitri Popov Date: Tue Jan 30 14:55:41 2018 +0100 Delete config.cfg commit 59fa6d0cedfd72ea9b8fe9392ad0215d8e7ea0d2 Author: Dmitri Popov Date: Tue Jan 30 14:51:11 2018 +0100 Update config.cfg commit 04feb7c260ec1202be9704cc55a0873fb3fa21a2 Author: Dmitri Popov Date: Mon Jan 29 15:45:55 2018 +0100 Remove mount share. Add config commit 1d84ece06bbec0436803a1cd9c956e6c4581c7e6 Author: Dmitri Popov Date: Mon Jan 29 15:43:58 2018 +0100 Create config.cfg commit 47ad5850cc7f47ee715e43a712e20e1b082890b3 Author: Dmitri Popov Date: Fri Jan 26 15:18:21 2018 +0100 Replace NFS with SHARE commit 1c2259d7e65ba35318c72bbbffa4bb371a2bba02 Author: Dmitri Popov Date: Fri Jan 26 14:38:31 2018 +0100 Add NFS mount and backup commit e37bc58168245df052daf21db9fd9a7f4185fdcf Author: Dmitri Popov Date: Fri Jan 26 13:20:17 2018 +0100 Add inactivity shutdown commit d759ac4e595f64b8ea748a0c7cde55b3cad51b2d Author: Dmitri Popov Date: Sat Jan 13 18:22:09 2018 +0100 Fix card id :monkey: commit c0ede01f95ca82a7991a64b6032998a6b855fa9c Author: Dmitri Popov Date: Sat Jan 13 18:04:41 2018 +0100 Exclude id file from backup :monkey: commit e1c6695d2191b989c0411e0883640540765a06b2 Author: Dmitri Popov Date: Sat Jan 13 17:54:48 2018 +0100 Fix card id :monkey: commit a0edc912ce9fdea13704da419c88c57296bb8d25 Author: Dmitri Popov Date: Sat Jan 13 17:52:31 2018 +0100 Fix card id :monkey: commit 4d9832c47b28548ccd02c442785f50c032663b77 Author: Dmitri Popov Date: Sat Jan 13 17:41:43 2018 +0100 Fix card id :monkey: commit 3bf32c33fb7096ff27b3067e1fe65e287fd29a04 Author: Dmitri Popov Date: Sat Jan 13 17:22:38 2018 +0100 Date/time as card id :monkey: commit acd75a2e6b31cb209449fc7454c0298c6b72613d Author: Dmitri Popov Date: Mon Jan 8 19:00:34 2018 +0100 Add else to handle existing .id file :monkey: commit e409e19bc8bb61733762f210aaee0b86ac5d1fa2 Author: Dmitri Popov Date: Mon Jan 8 18:46:38 2018 +0100 Improve card ID handling :monkey: --- README.md | 2 +- backup.sh | 66 +++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index bae6730..60c4fb8 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Save the changes. 2. Plug in the backup storage device (or camera, if you configured Little Backup Box as described above) 3. Plug in the card reader and wait till the Raspberry Pi shuts down -**Note:** To differentiate between different storage cards, the backup script assigns a random 8-digit identifying number to each card (this number is stored in the *CARD_ID* file in the root of the card). The contents of the card is saved on the storage device in a folder with the identifying number as its name. +**Note:** To differentiate between different storage cards, the backup script creates a datetime-based *.id* file in the root of each storage card. The name of the *.id* file is also used as the destination backup folder on the storage device. ## Problems? diff --git a/backup.sh b/backup.sh index 44de230..bc6b093 100755 --- a/backup.sh +++ b/backup.sh @@ -5,14 +5,31 @@ # to install the required packages and configure the system. # Specify devices and their mount points -STORAGE_DEV="sda1" -STORAGE_MOUNT_POINT="/media/storage" -CARD_DEV="sdb1" -CARD_MOUNT_POINT="/media/card" +# and other settings +STORAGE_DEV="sda1" # Name of the storage device +STORAGE_MOUNT_POINT="/media/storage" # Mount point of the storage device +CARD_DEV="sdb1" # Name of the storage card +CARD_MOUNT_POINT="/media/card" # Mount point of the storage card +GEO_REF="GEOREF.JPG" # Name of the reference photo to be used for geotagging +SHUTD="5" # Minutes to wait before shutdown due to inactivity + +# If there is a wpa_supplicant.conf file in the root of the storage device +# Rename the original config file, +# move wpa_supplicant.conf from the card to /etc/wpa_supplicant/ +# Reboot to enable networking +if [ -f "$STORAGE_MOUNT_POINT/wpa_supplicant.conf" ]; then + sudo sh -c "echo 100 > /sys/class/leds/led0/delay_on" + mv /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bak + mv "$STORAGE_MOUNT_POINT/wpa_supplicant.conf" /etc/wpa_supplicant/wpa_supplicant.conf + reboot +fi # 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} ] @@ -24,21 +41,13 @@ 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" -# If there is a wpa_supplicant.conf file in the root of the storage device -# Rename the original config file, -# move wpa_supplicant.conf from the card to /etc/wpa_supplicant/ -# Reboot to enable networking -if [ -f "$STORAGE_MOUNT_POINT/wpa_supplicant.conf" ]; then - sudo sh -c "echo 100 > /sys/class/leds/led0/delay_on" - mv /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bak - mv "$STORAGE_MOUNT_POINT/wpa_supplicant.conf" /etc/wpa_supplicant/wpa_supplicant.conf - reboot -fi - # Wait for a card reader or a camera CARD_READER=$(ls /dev/* | grep $CARD_DEV | cut -d"/" -f3) until [ ! -z $CARD_READER ] @@ -52,21 +61,30 @@ if [ ! -z $CARD_READER ]; then mount /dev/$CARD_DEV $CARD_MOUNT_POINT # # Set the ACT LED to blink at 500ms to indicate that the card has been mounted sudo sh -c "echo 500 > /sys/class/leds/led0/delay_on" - # Create the CARD_ID file containing a random 8-digit identifier if doesn't exist - if [ ! -f $CARD_MOUNT_POINT/CARD_ID ]; then - < /dev/urandom tr -cd 0-9 | head -c 8 > $CARD_MOUNT_POINT/CARD_ID + # Create a .id random identifier file if doesn't exist + cd $CARD_MOUNT_POINT + if [ ! -f *.id ]; then + touch $(date -d "today" +"%Y%m%d%H%M").id fi + ID_FILE=$(ls *.id) + ID="${ID_FILE%.*}" + cd + +# Set the backup path +BACKUP_PATH=$STORAGE_MOUNT_POINT/"$ID" # Log the output of the lsblk command for troubleshooting sudo lsblk > lsblk.log - -# Read the 8-digit identifier number from the CARD_ID file on the card -# 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" # Perform backup using rsync -rsync -avh $CARD_MOUNT_POINT/ $BACKUP_PATH +rsync -av --exclude "*.id" $CARD_MOUNT_POINT/ $BACKUP_PATH + +# Geotag photos if the reference photo exists +if [ -f "$STORAGE_MOUNT_POINT/$GEO_REF" ]; then + cd $STORAGE_MOUNT_POINT + exiftool −overwrite_original_in_place -r -ext jpg -tagsFromFile $GEO_REF -gps:all . +fi + # Turn off the ACT LED to indicate that the backup is completed sudo sh -c "echo 0 > /sys/class/leds/led0/brightness" fi From b2ebb0f4c85b15ae1bd089cc8a13262ae4307007 Mon Sep 17 00:00:00 2001 From: Dmitri Popov Date: Tue, 30 Jan 2018 20:02:05 +0100 Subject: [PATCH 2/2] Add libimage-exiftool-perl --- install-little-backup-box.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-little-backup-box.sh b/install-little-backup-box.sh index 2c09b0d..96269c5 100755 --- a/install-little-backup-box.sh +++ b/install-little-backup-box.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -sudo apt update && sudo apt dist-upgrade -y && sudo apt install acl git-core screen rsync exfat-fuse exfat-utils ntfs-3g minidlna gphoto2 -y +sudo apt update && sudo apt dist-upgrade -y && sudo apt install acl git-core screen rsync exfat-fuse exfat-utils ntfs-3g minidlna gphoto2 libimage-exiftool-perl -y sudo mkdir /media/card sudo mkdir /media/storage