diff --git a/README.md b/README.md index e2d206b..6c00da3 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,18 @@ Uncomment then the line below by removing *#*: Save the changes. -Keep in mind that in this case, the transferred files are saved in the */home/pi/BACKUP* directory on the system storage card. Make sure that the card you use with Raspberry Pi has adequate storage capacity. +Keep in mind that in this case, the transferred files are saved in the */home/pi/[CAMERA MODEL]* directory on the system storage card. Make sure that the card you use with Raspberry Pi has adequate storage capacity. **Important** Make sure that the camera is set to the MTP USB connection mode. +### Alternative Direct File Transfer Script + +Some cameras (notably Sony Alpha models) may not work with the default direct file transfer script. In this case, try the *gphoto-backup-alt.sh* script instead by enabling the following cron job as described above: + + #@reboot sudo /home/pi/little-backup-box/gphoto-backup-alt.sh > /home/pi/gphoto-backup-alt.log + +This script saves transferred files in the */home/pi/BACKUP* directory. + ## Usage 1. Boot the Raspberry Pi diff --git a/gphoto-backup-alt.sh b/gphoto-backup-alt.sh new file mode 100755 index 0000000..fb5d19d --- /dev/null +++ b/gphoto-backup-alt.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# IMPORTANT: +# Run the install-little-backup-box.sh script first +# to install the required packages and configure the system. + +# Specify a storage device and its mount point +STORAGE_MOUNT_POINT="/home/pi/BACKUP" + +# Set the ACT LED to heartbeat +sudo sh -c "echo heartbeat > /sys/class/leds/led0/trigger" + +# Create the target directory if it doesn't exist +if [ ! -d "$STORAGE_MOUNT_POINT" ]; then + mkdir $STORAGE_MOUNT_POINT +fi + +# 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 transfer files from the camera +# Rename the transferred files using the YYYYMMDD-HHMMSS format +cd $STORAGE_MOUNT_POINT +gphoto2 --get-all-files --skip-existing --filename=%Y%m%d-%H%M%S.%C +# Turn off the ACT LED to indicate that the backup is completed +sudo sh -c "echo 0 > /sys/class/leds/led0/brightness" + +# Shutdown +shutdown -h now diff --git a/gphoto-backup.sh b/gphoto-backup.sh index 9a10d51..c52910b 100755 --- a/gphoto-backup.sh +++ b/gphoto-backup.sh @@ -1,16 +1,15 @@ #!/usr/bin/env bash +# IMPORTANT: +# Run the install-little-backup-box.sh script first +# to install the required packages and configure the system. + # Specify a storage device and its mount point -STORAGE_MOUNT_POINT="/home/pi/BACKUP" +HOME_DIR="/home/pi" # Set the ACT LED to heartbeat sudo sh -c "echo heartbeat > /sys/class/leds/led0/trigger" -# Create the target directory if it doesn't exist -if [ ! -d "$STORAGE_MOUNT_POINT" ]; then - mkdir $STORAGE_MOUNT_POINT -fi - # Wait for camera DEVICE=$(gphoto2 --auto-detect | grep usb | cut -b 36-42 | sed 's/,/\//') while [ -z ${DEVICE} ] @@ -19,6 +18,11 @@ while [ -z ${DEVICE} ] DEVICE=$(gphoto2 --auto-detect | grep usb | cut -b 36-42 | sed 's/,/\//') done +# Obtain camera model +# Create the target directory with the camera model as its name +CAMERA=$(gphoto2 --summary | grep "Model" | cut -d: -f2 | tr -d '[:space:]') +STORAGE_MOUNT_POINT="$HOME_DIR/$CAMERA" + # 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" diff --git a/install-little-backup-box.sh b/install-little-backup-box.sh index 96269c5..b82ac22 100755 --- a/install-little-backup-box.sh +++ b/install-little-backup-box.sh @@ -13,6 +13,7 @@ git clone https://github.com/dmpop/little-backup-box.git crontab -l | { cat; echo "@reboot sudo /home/pi/little-backup-box/backup.sh > /home/pi/little-backup-box.log"; } | crontab crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/gphoto-backup.sh > /home/pi/gphoto-backup.log"; } | crontab +crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/gphoto-backup-alt.sh > /home/pi/gphoto-backup-alt.log"; } | crontab sudo sed -i 's|'media_dir=/var/lib/minidlna'|'media_dir=/media/storage'|' /etc/minidlna.conf sudo service minidlna start