#!/bin/sh HOST='ioj-ds1821.local' MAC="umac-128-etm@openssh.com" CIPHER="aes128-ctr" SRC=$(echo "$1" | sed 's#/$##') TIMESTAMP="$(date '+%Y%m%d%H%M%S')" VOLUME_PATH=$(echo "$1" | sed 's#^\(/Volumes/[^\/]*\).*$#\1#') VOLUME_NAME=$(echo "$1" | sed 's#^/Volumes/\([^\/]*\).*$#\1#') VOLUME_UUID=$(diskutil info "${VOLUME_PATH}" 2> /dev/null | grep 'Volume UUID:' | sed 's# *Volume UUID: *##') VOLUME_DISK=$(df "${VOLUME_PATH}" | tail -n1 | awk '{print $1}' | sed 's/\(disk[0-9][0-9]*\)s[0-9][0-9]*/\1/g') #echo "Disk = $VOLUME_DISK" #exit 1 SEP='' mkdir logs if [ -f "$1" ]; then VOLUME_DIR=$(echo "$1" | sed 's#^/Volumes/[^\/]*/\(.*\)/[^\/]*$#\1#') elif [ -d "$1" ]; then VOLUME_DIR=$(echo "$1" | sed -E "s#^${VOLUME_PATH}/?##" | sed 's#/##' ) if [ "$VOLUME_DIR" == "" ]; then SEP='' fi elif [ ! -e "$1" ]; then exit -1 fi #DST="${VOLUME_NAME} ${VOLUME_UUID}/${VOLUME_DIR}${SEP}" DST="by-uuid/${VOLUME_UUID}/${VOLUME_DIR}${SEP}" LOG="logs/${VOLUME_UUID}-${VOLUME_NAME}-${TIMESTAMP}.log" TARGET="timrutter@${HOST}:'/volume1/Storage/HDDs/${DST}'" echo "SRC='$SRC'" #echo "DST='$DST'" echo "TARGET='$TARGET'" #echo "DIR='$VOLUME_DIR'" read -p "Are you sure? " -n 1 -r echo # (optional) move to a new line if [[ ! $REPLY =~ ^[Yy]$ ]] then echo 'Bye!' exit -2 fi read -p "Run dot_clean on '$SRC'? " -n 1 -r echo # (optional) move to a new line if [[ ! $REPLY =~ ^[Nn]$ ]] then echo "Cleaning..." find "$SRC" -maxdepth 1 -mindepth 1 -not -name '*.backupdb' -exec dot_clean -n {} + &>/dev/null fi RSYNC_OPTIONS="" #RSYNC_OPTIONS="--delete --delete-excluded" read -p "Dry run? " -n 1 -r echo # (optional) move to a new line if [[ ! $REPLY =~ ^[Nn]$ ]] then RSYNC_OPTIONS="$RSYNC_OPTIONS --dry-run" fi read -p "Full sync aka DELETE? " -n 1 -r echo # (optional) move to a new line if [[ $REPLY =~ ^[Yy]$ ]] then RSYNC_OPTIONS="$RSYNC_OPTIONS --delete --delete-excluded" fi echo "rsync options='$RSYNC_OPTIONS'" read -p "Pause, press any key... " -n 1 -r echo "Running..." /usr/bin/rsync -tirl \ --progress --stats $RSYNC_OPTIONS \ --exclude={'*.backupdb/*','.Trashes','.Spotlight-V100','.AppleDouble','.DS_Store','Desktop DF','Desktop DB','.apdisk'.'.Trashes','.fseventsd','.TemporaryItems','.Spotlight-V100','.DocumentRevisions-V100','.com.apple.timemachine*','tmbootpicker.efi','exclude-from-transfer'} \ -e "ssh -c ${CIPHER} -o 'MACs ${MAC}'" \ --rsync-path="/usr/local/bin/rsync" \ "$SRC/" "$TARGET" \ 2>&1 | tee -a "${LOG}" echo "Done Transfering ''" ssh "timrutter@${HOST}" "ln -snf ../by-uuid/${VOLUME_UUID} '/volume1/Storage/HDDs/by-name/${VOLUME_NAME}'" read -p "Do you want to eject the volume '$VOLUME_NAME'? " -n 1 -r echo # (optional) move to a new line if [[ $REPLY =~ ^[Yy]$ ]] then diskutil eject "$VOLUME_PATH" exit 0 fi