[cluster] deploy: add -r and -R options (rsync)
The -r option allows to use prsync instead of pscp. The -R option is the same, except the --delete option is passed to rsync.
This commit is contained in:
parent
044f120fcc
commit
5a44742c28
|
@ -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)
|
||||
|
|
|
@ -15,8 +15,14 @@
|
|||
print_usage()
|
||||
{
|
||||
echo "Usage:"
|
||||
echo " $0 [-P] [-l login] <hosts_list> <file1> [file2 [...]]"
|
||||
echo "-P: transfer files in parallel instead of one by one."
|
||||
echo " $0 [-P] [-r|-R] [-l login] <hosts_list> <file1> [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
|
||||
|
|
Loading…
Reference in New Issue