aboutsummaryrefslogtreecommitdiff
path: root/ssync-fetch
diff options
context:
space:
mode:
Diffstat (limited to 'ssync-fetch')
-rwxr-xr-xssync-fetch60
1 files changed, 44 insertions, 16 deletions
diff --git a/ssync-fetch b/ssync-fetch
index 24b9c59..0fab1b9 100755
--- a/ssync-fetch
+++ b/ssync-fetch
@@ -2,14 +2,16 @@
USAGE="ssync-fetch [options] QUEUE_FILE DEST_DIR
OPTIONS
- -r REMOTE_HOST
- remote host to download from such as user@hostname
- username can be omitted if identical to $USER
- or if set in ssh_config
- -k KEY_FILE
- ssh-key file to use (needs to be non-interactive)
- optional: will use default session key
- or key set in ssh_config for REMOTE_HOST
+ -r REMOTE_HOST
+ remote host to download from such as user@hostname
+ username can be omitted if identical to $USER
+ or if set in ssh_config
+ -k KEY_FILE
+ ssh-key file to use (needs to be non-interactive)
+ optional: will use default session key
+ or key set in ssh_config for REMOTE_HOST
+ -b BACKEND
+ sftp (default) | rsync
-v verbose logging
-h print this message"
@@ -17,7 +19,7 @@ USAGE="ssync-fetch [options] QUEUE_FILE DEST_DIR
function verbose_log {
if [ ! -z "$VERBOSE_FLAG" ]; then
- echo "$@"
+ echo "$@"
fi
}
function lines {
@@ -30,9 +32,11 @@ KEY_FILE_FLAG=
KEY_FILE_ARG=
REMOTE_HOST_FLAG=
REMOTE_HOST_ARG=
+BACKEND_FLAG=
+BACKEND_ARG=
VERBOSE_FLAG=
-while getopts "hvr:k:" opt; do
+while getopts "hvr:k:b:" opt; do
case "${opt}" in
h) echo "$USAGE"
exit 1
@@ -45,6 +49,9 @@ while getopts "hvr:k:" opt; do
r) REMOTE_HOST_FLAG=1
REMOTE_HOST_ARG="${OPTARG}"
;;
+ b) BACKEND_FLAG=1
+ BACKEND_ARG="${OPTARG}"
+ ;;
esac
done
@@ -81,6 +88,19 @@ elif [ -z "$REMOTE_HOST_ARG" ]; then
exit 1
fi
+if [ -z "$BACKEND_FLAG" ]; then
+ BACKEND="sftp"
+else
+ BACKEND=$BACKEND_ARG
+fi
+
+if [ "$BACKEND" != "sftp" ]; then
+ if [ "$BACKEND" != "rsync" ]; then
+ echo "Invalid backend $BACKEND"
+ exit 1
+ fi
+fi
+
# CONFIGURATIONS
ssh_id_param=""
@@ -98,13 +118,21 @@ ts=$(date +%s)
verbose_log "Writing temp files to ${tmp_dir} with timestamp ${ts}"
# GENERATE BATCH
-batch_file=$tmp_dir/batch_${ts}
-verbose_log "Converting the queue file to sftp batch file: ${batch_file}"
-cat $QUEUE_FILE | xargs -I{} echo "@reget {} ${real_dest}/" >> $batch_file
-verbose_log "Beginning download"
-verbose_log "sftp -N ${ssh_id_param} -b ${batch_file} ${REMOTE_HOST_ARG}"
+if [ "$BACKEND" == "sftp" ]; then
+ batch_file=$tmp_dir/batch_${ts}
+ verbose_log "Converting the queue file to sftp batch file: ${batch_file}"
+ cat $QUEUE_FILE | xargs -I{} echo -e "@reget {} ${real_dest}/" > $batch_file
+
+ verbose_log "Beginning download"
+ verbose_log "sftp -N ${ssh_id_param} -b ${batch_file} ${REMOTE_HOST_ARG}"
-sftp -N ${ssh_id_param} -b ${batch_file} ${REMOTE_HOST_ARG}
+ sftp -N ${ssh_id_param} -b ${batch_file} ${REMOTE_HOST_ARG}
+elif [ "$BACKEND" == "rsync" ]; then
+ verbose_log "Fetching files from queue file: $QUEUE_FILE"
+ verbose_log "Beginning download"
+ verbose_log "rsync --files-from=${QUEUE_FILE} rsync://${REMOTE_HOST_ARG} ${real_dest}"
+ rsync -av --no-relative --files-from=${QUEUE_FILE} ${REMOTE_HOST_ARG}:/ ${real_dest}
+fi
verbose_log "ssync-fetch finished"