#!/bin/bash # # uncomment this line for debugging # set -x # ####################################################################### # # svnmirror.sh v0.0.1 # # this script syncs changes from a developer repository to a # _READONLY_public_repository_ # # it supports pushing or pulling the changes via ssh and svn tools. # its intended to be run manually or from cron. # ####################################################################### # # things you have to take care of: # # 1. you need write access to the directory structure on both boxes # for more see the warning at: # http://svnbook.red-bean.com/html-chunk/ch06s03.html # # 2. for running it from cron i suggest the use of the ssh agent e.g # via keychain # in general read "man ssh-agent" and "man ssh-keygen". # # 3. don't run it from post commit scripts it can lead to broken public # repositories! # # 4. you do not have to be afraid of the public repos. if the pipe is # broken nothing will be committed to it. # 21:40:47 <@sussman> tberman: welcome to atomic commits. # # 5. for local syncing use "svnadmin hotcopy" # see: "svnadmin help hotcopy" # ####################################################################### # # Authors: # - Marcus Rückert # # with suggestions from: # - tberman (#svn at freenode) # - he actually needed such a script :) # - Erik Huelsmann # - the little if for remote version :) # - status reply # - Ben Collins-Sussman # - for some help with the svn commands # - Martin Furter # - suggested svnlook instead of some long "svn pl" # - suggested comparing local and remote version. # it always dumps the last version if they are in sync. # we do not want this. # - thanks for actually testing the script. :) # # TODO: # - maybe i should add cmdline switches for the parameters # # License: # the same as svn itself. for latest version check: # http://svn.collab.net/repos/svn/trunk/subversion/LICENSE # # thanks to the subversion team for their great work # # Links: # # if you do not like my solution check: # - http://svn.collab.net/repos/svn/trunk/contrib/client-side/svn-push/svn-push.c # ####################################################################### # # config # # everything starting with "R" refers to the remote host # with "L" to the local host # ####################################################################### # # mode: # # push == from local repository to remote (readonly) repository # pull == from remote repository to local (readonly) repository # MODE="push" # # local host # # # -c blowfish -C to speed up the transfer a bit :) # LSSH="/usr/bin/ssh -c blowfish -C" LSVNADMIN="/usr/bin/svnadmin" LSVNLOOK="/usr/bin/svnlook" # LREPOS="/path/to/repos" # # remote host # RSVNLOOK="/usr/bin/svnlook" RSVNADMIN="/usr/bin/svnadmin" # RREPOS="/path/to/repos" RHOST="host" RUSER="user" # # additional commands you want to run before loading the dump in to the repos # e.g. setting umask or change group via newgrp # # make sure the last char is a ";" # LADDITIONAL="" RADDITIONAL="" ####################################################################### # # the actual script # ####################################################################### # # uncomment this line if you want to use keychain. # you maybe have to tweak the path to the script # # source ~/.keychain/$(uname -n)-sh # # getting version of the remote repository # RVERSION=$(ssh ${RUSER}@${RHOST} ${RSVNLOOK} youngest ${RREPOS}) # # syncing # if [ -n "${RVERSION}" ] ; then # # getting version of the local repository # ${LADDITIONAL} LVERSION=$(${LSVNLOOK} youngest ${LREPOS}) if [ -n "${LVERSION}" ] ; then if [ ${RVERSION} -ne ${LVERSION} ] ; then if [ $MODE = "push" ] ; then echo -n "syncing ${RVERSION} to ${LVERSION} to ${RHOST} "; ${LSVNADMIN} dump --incremental -r$((${RVERSION}+1)):${LVERSION} ${LREPOS} |\ ${LSSH} $RUSER@$RHOST "${RADDITIONAL} ${RSVNADMIN} load ${RREPOS}" &&\ echo "successfull completed." ||\ echo "failed" elif [ $MODE = "pull" ] ; then echo -n "syncing ${RVERSION} to ${LVERSION} from ${RHOST} "; ${LSSH} ${RUSER}@${RHOST} \ "${RADDITIONAL} ${RSVNADMIN} dump --incremental -r$((${LVERSION}+1)):${RVERSION} ${RREPOS}" |\ ${LSVNADMIN} load ${LREPOS} &&\ echo "successfull completed." ||\ echo "failed" else echo "invalid mode \"${MODE}\" specified!" fi else echo "both repositories are already at ${LVERSION}" fi else echo "getting version of local repository failed" fi else echo "getting version of remote repository failed" fi