diff options
author | Jonas Smedegaard <dr@jones.dk> | 2002-02-28 14:09:04 +0000 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2002-02-28 14:09:04 +0000 |
commit | cafcd5d4368e57f162a641ed3f4835ecb5a6d391 (patch) | |
tree | 56166fbf16289d8b388cf0f1f9b51e28c3c4bdf9 /localsyncthis |
Initial revision
Diffstat (limited to 'localsyncthis')
-rwxr-xr-x | localsyncthis | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/localsyncthis b/localsyncthis new file mode 100755 index 0000000..b6a725d --- /dev/null +++ b/localsyncthis @@ -0,0 +1,92 @@ +#!/bin/sh + +# Initial setup +prg=$(basename $0) +copyright="(C) 2000-2002 Jonas Smedegaard <dr@jones.dk>" +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 [<options>] host [path [path...]] + or: $prg [<options>] \"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 |