From cafcd5d4368e57f162a641ed3f4835ecb5a6d391 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Thu, 28 Feb 2002 14:09:04 +0000 Subject: Initial revision --- localsyncthis | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 localsyncthis (limited to 'localsyncthis') 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 " +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 -- cgit v1.2.3