diff --git a/cluster/README b/cluster/README index bc04b4b..dc70f26 100644 --- a/cluster/README +++ b/cluster/README @@ -56,8 +56,21 @@ Dependency: parallel-ssh (pssh) = cluster-deploy.sh = Deploy one or more files in parallel on every host of the hosts' list. +The files are copied in the remote user's home directory. + By default, the files are transfered one by one, to be sure to notice the errors for each file (bad permissions, out of space, etc.), but the -P option allows to transfer them all together. -Dependency: parallel-scp (pscp) +While it is possible to transfer directories with the default option, to +synchronise directories one would rather use the -r option, that uses +prsync rather than pscp to transfer the files. With the -R option, the +remote files that are not in the local copy will be deleted (rsync's +--delete option). With both options, the transfer is done with rsync's +-a (archive) option. + +Please note that unlike rsync, prsync cannot handle multiple local +files, therefore the -P option is ignored when passed along with -r or +-R. + +Dependencies: parallel-scp (pscp), parallel-rsync (prsync) diff --git a/cluster/cluster-deploy.sh b/cluster/cluster-deploy.sh index 05d1e91..40eb289 100755 --- a/cluster/cluster-deploy.sh +++ b/cluster/cluster-deploy.sh @@ -15,8 +15,14 @@ print_usage() { echo "Usage:" - echo " $0 [-P] [-l login] [file2 [...]]" - echo "-P: transfer files in parallel instead of one by one." + echo " $0 [-P] [-r|-R] [-l login] [file2 [...]]" + echo + echo "Options:" + echo " -P: transfer files in parallel instead of one by one if possible" + echo " (ignored when -r or -R is used)." + echo " -r: use prsync instead of pscp." + echo " -R: use prsync with option --delete (delete remote files that are" + echo " not in the local copy)." } # Parse the optional arguments @@ -31,6 +37,14 @@ while [ $# -gt 2 ] ; do PARALLEL=1 shift ;; + "-r") + RSYNC=1 + shift + ;; + "-R") + DELETE=1 + shift + ;; *) break ;; @@ -46,11 +60,33 @@ if [ $# -lt 2 ] ; then exit 1 fi +# Check the usage of -r and -R +if [ "$DELETE" = "1" ] ; then + if [ "$RSYNC" = "1" ] ; then + echo "Use either -r or -R, but not both!" + echo + print_usage + exit 2 + fi + RSYNC=1 + DELETE="-X --delete" +fi + +# Ignore -P if rsync is going to be used +if [ "$RSYNC" = "1" -a "$PARALLEL" = "1" ] ; then + echo "Cannot transfer in parallel when using rsync: ignoring -P." + PARALLEL="" +fi + # Check dependencies PSCP=$(command -v parallel-scp || command -v pscp.pssh || command -v pscp) -if [ "$PSCP" = "" ] ; then +PRSYNC=$(command -v parallel-rsync || command -v prsync) +if [ "$RSYNC" = "" -a "$PSCP" = "" ] ; then echo "Parallel SSH (pssh) is required for this script to work." exit 4 +elif [ "$PRSYNC" = "" ] ; then + echo "Parallel rsync (prsync) is required for this script to work." + exit 5 fi # Hosts' list file @@ -72,5 +108,9 @@ fi # ... or one by one for FILE in "$@" ; do echo "Deploying '$FILE'..." - $PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" ~ + if [ "$RSYNC" = "1" ] ; then + $PRSYNC -a $DELETE $LOGIN -h "$HOSTS" -- "$FILE" ~ + else + $PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" ~ + fi done