From de0e7733ccd70014cbd1571131385f0dec69cff9 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Tue, 24 Nov 2015 23:38:23 -0500 Subject: New import script to be used with devmon. --- import/photobox_import2.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 import/photobox_import2.sh diff --git a/import/photobox_import2.sh b/import/photobox_import2.sh new file mode 100755 index 0000000..4492fc6 --- /dev/null +++ b/import/photobox_import2.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +readonly backup_root=/tmp/backup +readonly pending_root=/tmp/pending +readonly photoregex='.*\(jpg\|raf\|cr2\)' + +#readonly backup_root=/btrfs/staging/import_tmp +#readonly pending_root=/btrfs/storage/pending-photos +readonly input="$1" + +make_unique() { + if [[ ! -d "$1" ]]; then + echo "$1" + else + extension=1 + while [[ -d "${1}-${extension}" ]]; do + extension=$(($extension + 1)) + done + echo "${1}-${extension}" + fi +} + +readonly backup_path="$(make_unique $backup_root/$(date +%Y-%m-%d)-$(basename $input))" +readonly pending_path="$(make_unique $pending_root/$(date +%Y-%m-%d))" + +( + flock -x -w 120 200 || exit 1 + mkdir -p "$backup_path" + rsync -Hvax "$input/." "$backup_path/." + echo "Contents backed up to: $backup_path" + echo "pending_path: $pending_path" + + if [[ -d "$backup_path/DCIM" && \ + -n $(find "$backup_path/DCIM" -iregex "$photoregex" -print -quit) ]]; then + echo "Found photos" + echo mkdir -p "${pending_path}.importing" + echo rsync -avx "$backup_path"/DCIM/*/* "${pending_path}.importing/" + echo mv "${pending_path}.importing" "${pending_path}" + fi + + echo "Deleting original files" + rsync -Hvax --remove-source-files "$input/." "$backup_path/." + echo umount "${input}" +) 200>/tmp/photobox_import2.lock | systemd-cat -t photobox_import -- cgit v1.2.3