From 13420e6d83e19c3b2b9ebb8fa58580c40a672a1e Mon Sep 17 00:00:00 2001 From: deajan Date: Mon, 18 Nov 2013 21:16:31 +0100 Subject: [PATCH] Added ssh uri support --- CHANGELOG.md | 3 ++- README.md | 1 + osync.sh | 40 +++++++++++++++++++++++++++------------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22a8f27..0479da9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,6 @@ SHORT FUTURE IMPROVEMENTS (post v1.0) - Sync and delete propagation function merge (master and slave functions are the same, reduces code size and maintain effort) - Tree function merge (current and after tree functions are the same except for output filename and logging, reduces code size and maintain effort) - Tree functions execute piped commands (grep, awk) on master when launched on remote slave which can cause more bandwith usage -- Fast sync mode should also work with remote systems FAR FUTURE IMPROVEMENTS ----------------------- @@ -21,6 +20,8 @@ KNOWN ISSUES RECENT CHANGES -------------- +- Changed conf file default format for ssh uri (old format is still compatible) +- Added ssh uri support for slave replicas - Improved execution hooks logs - Various bugfixes introduced with function merge - Added basic MacOS X support (yet not fully tested) diff --git a/README.md b/README.md index 2050796..417994b 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ While quick sync mode is convenient to do fast sync sceanrios, a configuration f QuickSync example: $ ./osync.sh --master=/path/to/dir1 --slave=/path/to/dir2 + $ ./osync.sh --master=/path/to/dir1 --slave=ssh://user@host.com:22//path/to/dir2 --rsakey=/home/user/.ssh/id_rsa Configuration files example: diff --git a/osync.sh b/osync.sh index d970a59..68c5d7d 100755 --- a/osync.sh +++ b/osync.sh @@ -2,8 +2,8 @@ ###### Osync - Rsync based two way sync engine with fault tolerance ###### (L) 2013 by Orsiris "Ozy" de Jong (www.netpower.fr) -OSYNC_VERSION=0.99RC2 -OSYNC_BUILD=1611201301 +OSYNC_VERSION=0.99RC2-qs +OSYNC_BUILD=1811201301 DEBUG=no SCRIPT_PID=$$ @@ -1505,20 +1505,30 @@ function Init ## Test if slave dir is a ssh uri, and if yes, break it down it its values if [ "${SLAVE_SYNC_DIR:0:6}" == "ssh://" ] then - slave_is_remote=1 + REMOTE_SYNC="yes" # remove leadng 'ssh://' uri=${SLAVE_SYNC_DIR#ssh://*} # remove everything after '@' - uri2=${uri%@*} - user=${uri2%;*} - fingerprint=${uri2#*fingerprint=} + _first_part=${uri%@*} + REMOTE_USER=${_first_part%;*} + #fingerprint=${_first_part#*fingerprint=} + if [ "$SSH_RSA_PRIVATE_KEY" == "" ] + then + SSH_RSA_PRIVATE_KEY=~/.ssh/id_rsa + fi # remove everything before '@' - uri3=${uri#*@} - host=${uri3%%:*} - REMOTE_USER=${SLAVE_SYNC_DIR} - REMOTE_HOST=${SLAVE_SYNC_DIR} - REMOTE_PORT=${SLAVE_SYNC_DIR} + _last_part=${uri#*@} + _last_part2=${_last_part%%/*} + # remove last part if no port defined + REMOTE_HOST=${_last_part2%%:*} + if [[ "$_last_part2" == *":"* ]] + then + REMOTE_PORT=${_last_part2##*:} + else + REMOTE_PORT=22 + fi + SLAVE_SYNC_DIR=${_last_part#*/} fi ## Rsync does not like spaces in directory names, considering it as two different directories. Handling this schema by escaping space @@ -1650,7 +1660,7 @@ function Usage echo "" echo "You may use Osync with a full blown configuration file, or use its default options for quick command line sync." echo "Normal usage: osync /path/to/conf.file [--dry] [--silent] [--verbose] [--no-maxtime] [--force-unlock]" - echo "Quick usage: osync --master=/path/to/master/replica --slave=/path/to/slave/replica [--dry] [--silent] [--verbose] [--no-max-time] [--force-unlock]" + echo "Quick usage: osync --master=/path/to/master/replica --slave=/path/to/slave/replica [--rsakey=/path/to/id_rsa] [--dry] [--silent] [--verbose] [--no-max-time] [--force-unlock]" echo "" echo "--dry: will run osync without actually doing anything; just testing" echo "--silent: will run osync without any output to stdout, usefull for cron jobs" @@ -1660,7 +1670,8 @@ function Usage echo "" echo "Quick usage only:" echo "--master= : Specify master replica path. Will contain state and backup directory." - echo "--slave= : Spacift slave replica path. Will contain backup directory." + echo "--slave= : Specify local or remote path for slave replica. Can be a ssh uri like ssh://user@host.com:22//path/to/slave/replica" + echo "--rsakey= : Specify alternative path to rsa private key for ssh connection to slave replica." exit 128 } @@ -1717,6 +1728,9 @@ do SLAVE_SYNC_DIR=${i##*=} no_maxtime=1 ;; + --rsakey=*) + SSH_RSA_PRIVATE_KEY=${i##*=} + ;; esac done