commit 81386d27292ed8d5b44094517883ecfc15373e1e Author: Dmitri Popov Date: Tue Dec 27 16:43:39 2016 +0100 Initial commit :rocket: diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..25c6bb7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.directory diff --git a/README.md b/README.md new file mode 100644 index 0000000..c062c78 --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# Little Backup Box + +Bash shell scripts that transform a Raspberry Pi (or any single-board computer running a Debian-based Linux distribution) into an inexpensive, fully-automatic, pocketable photo backup and streaming device. + + + +## Installation + +Install Git and screen: + + sudo apt install git-core screen + +Clone the Little Backup Box Git repository on your Raspberry Pi: + + git clone https://gitlab.com/dmpop/little-backup-box.git + +Switch to the *little-backup-box* directory and make the *install-little-backup-box.sh* script executable: + +``` +cd little-backup-box +chmod +x install-little-backup-box.sh +``` + +Run the installer script: + + ./install-little-backup-box.sh + +## Usage + +1. Boot the Raspberry Pi +2. Plug in the backup storage device +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. + +# Problems? + +Please report bugs and issues in the [Issues](https://gitlab.com/dmpop/little-backup-box/issues) section. + +## Linux Photography + +Little Backup Box is a part of a streamlined and automated Linux-based photographic workflow described in the [Linux Photography](https://gumroad.com/l/linux-photography) book. The book provides step-by-step instructions on building a Raspberry Pi-based photo backup device running the Little Backup Box script. Get your copy at [Gumroad](https://gumroad.com/l/linux-photography). + + + + +## Author + +Dmitri Popov [dmpop@linux.com](mailto:dmpop@linux.com) + +## License + +The [GNU General Public License version 3](http://www.gnu.org/licenses/gpl-3.0.en.html) diff --git a/backup.sh b/backup.sh new file mode 100755 index 0000000..5ed8efd --- /dev/null +++ b/backup.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# 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 +STORAGE_DEV="sda1" +STORAGE_MOUNT_POINT="/media/storage" +CARD_DEV="sdb1" +CARD_MOUNT_POINT="/media/card" + +# Set the ACT LED to heartbeat +sudo sh -c "echo heartbeat > /sys/class/leds/led0/trigger" + +# 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 + +# 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" + +# Wait for a card reader or a camera +CARD_READER=$(ls /dev/* | grep $CARD_DEV | cut -d"/" -f3) +until [ ! -z $CARD_READER ] + do + sleep 1 + CARD_READER=$(ls /dev/sd* | grep $CARD_DEV | cut -d"/" -f3) +done + +# If the card reader is detected, mount it and obtain its UUID +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 + fi + # 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 +# 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 diff --git a/gphoto-backup.sh b/gphoto-backup.sh new file mode 100644 index 0000000..9aab077 --- /dev/null +++ b/gphoto-backup.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +# Specify a storage device and its mount point +STORAGE_DEV="sda1" +STORAGE_MOUNT_POINT="/media/storage" + +# Set the ACT LED to heartbeat +sudo sh -c "echo heartbeat > /sys/class/leds/led0/trigger" + +# 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 + +# 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" + +# Wait for camera +DEVICE=$(gphoto2 --auto-detect | grep usb | cut -b 36-42 | sed 's/,/\//') +while [ -z ${DEVICE} ] + do + sleep 1 + DEVICE=$(gphoto2 --auto-detect | grep usb | cut -b 36-42 | sed 's/,/\//') +done + +# Set the ACT LED to blink at 500ms to indicate that the camera has been detected +sudo sh -c "echo 500 > /sys/class/leds/led0/delay_on" + +# Switch to STORAGE_MOUNT_POINT and create a directory with current date as its name +cd $STORAGE_MOUNT_POINT +mkdir "`date --iso-8601`" && cd $_ +# Transfer new files to the USB storage device +#gphoto2 --get-all-files +gphoto2 --new +# Rename files using ExifTool based on EXIF date and time data +exiftool -r -d %Y%m%d-%H%M%S.%%e "-FileName /sys/class/leds/led0/brightness" +# Shutdown +shutdown -h now diff --git a/ichigo.svg b/ichigo.svg new file mode 100644 index 0000000..4b32cf1 --- /dev/null +++ b/ichigo.svg @@ -0,0 +1,229 @@ + +image/svg+xml \ No newline at end of file diff --git a/install-little-backup-box.sh b/install-little-backup-box.sh new file mode 100755 index 0000000..1e2bb54 --- /dev/null +++ b/install-little-backup-box.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +sudo apt update && sudo apt dist-upgrade -y && sudo apt install rsync exfat-fuse exfat-utils ntfs-3g minidlna gphoto2 -y + +sudo mkdir /media/card +sudo mkdir /media/storage +sudo chown -R pi:pi /media/storage +sudo chmod -R 775 /media/storage +sudo setfacl -Rdm g:pi:rw /media/storage + +crontab -l | { cat; echo "@reboot sudo /home/pi/little-backup-box/backup.sh"; } | crontab + +sudo sed -i 's|'media_dir=/var/lib/minidlna'|'media_dir=/media/storage'|' /etc/minidlna.conf +sudo service minidlna start + +echo "------------------------" +echo "All done! Please reboot." +echo "------------------------"