#!/bin/sh # Initial setup prg=$(basename $0) copyright="(C) 2000-2002 Jonas Smedegaard " V='' action='' hosts='' rsync_opts='-avrtz --delete --force' ssh_opts='' localdir='' remotedir='' args='' while [ $# -gt 0 ]; do case $1 in -h|--help) echo "$prg, $copyright usage: $prg [] host [path [path...]] or: $prg [] \"host [host...]\" [path [path...]] where options are the following: -v|--verbose Verbose mode --host Hostname(s) of remote host(s) -l|--localdir Local base directory (only if path specified) -r|--remotedir Remote base directory -p|--port ssh port number --ssh-opts Arbitrary ssh options -h|--help This help text -* Arbitrary rsync options --upload mirrors from local dir to remote dir. --download does the opposite. If no path specified, current working directory is used." exit 0 ;; -v|--verbose) V=1; rsync_opts="$rsync_opts --progress --stats";; --download) action=download;; --upload) action=upload;; --test|--dry-run) rsync_opts="$rsync_opts --dry-run";; --force|--whole-file) rsync_opts="$rsync_opts --whole-file";; --host) hosts="$hosts $2"; shift;; -l|--localdir) localdir="$2"; shift;; -r|--remotedir) remotedir="$2"; shift;; -p|--port) ssh_opts="$ssh_opts -p $2"; shift;; --ssh-opts) ssh_opts="$ssh_opts $2"; shift;; -*) rsync_opts="$rsync_opts $1";; *) args="$args $1";; esac shift done set -- $args if [ -z $hosts ]; then hosts=$1 shift fi if [ -z $hosts ]; then echo "$prg error: Hostname missing!" echo $0 --help exit 1 fi if [ "x$1" = "x" ]; then workdirs=`pwd` localdir='' else workdirs=$@ fi for workdir in $workdirs; do for host in $hosts; do here="$localdir$workdir" there="$host:$remotedir$workdir" case $action in download) rsync --rsh="ssh $ssh_opts" $rsync_opts $there/ $here [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts $there/ $here ;; upload) rsync --rsh="ssh $ssh_opts" $rsync_opts $here/ $there [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts $here/ $there ;; *) echo "$prg error: You need to specify either --upload or --download!" echo $0 --help exit 1 ;; esac done done