commit 59fb6ef3ad7f5c967293a909a768c20c9cd7ddd8 parent e55fdf495157891cc7f0f3d029df4a12c64956b9 Author: Jan Pobrislo <ccx@webprojekty.cz> Date: Wed, 19 Feb 2014 03:28:06 +0100 pure sh pre/post xfer Diffstat:
| M | bin/snap.rsync.post | | | 41 | ++++++++++++++++++++++++----------------- |
| C | bin/snap.rsync.post -> bin/snap.rsync.post.zsh | | | 0 | |
| M | bin/snap.rsync.pre | | | 28 | ++++++++++++++++++++++------ |
| M | rsyncd.conf | | | 6 | +++--- |
4 files changed, 49 insertions(+), 26 deletions(-)
diff --git a/bin/snap.rsync.post b/bin/snap.rsync.post @@ -1,23 +1,30 @@ -#!/bin/zsh +#!/bin/sh exec 1>&2 -env | grep RSYNC +env | grep RSYNC | sort | tr '\n' '\t'; echo set -x -[[ $RSYNC_MODULE_NAME != 'snaprep_new' ]] && exit 0 +case $RSYNC_MODULE_NAME in + (*.push) ;; + (*) exit 1;; +esac -f=( $RSYNC_MODULE_PATH/.snapshot.[0-9]*(N) ) -if (($#f == 0)); then - exit 0 -elif (($#f > 1)); then - rm -rf $f || exit $? -else - ts=${f##*.} - d=$RSYNC_MODULE_PATH:h - if [[ -a $d/.snapshot.$ts ]]; then - rm -rf $f || exit $? - else - rsync -aA --exclude=/.snapshot.\* --link-dest=$RSYNC_MODULE_PATH/ $RSYNC_MODULE_PATH/ $d/$ts/ || exit $? - mv $f $d/ || exit $? - fi +for m in $RSYNC_MODULE_PATH/.snapshot.[0-9]*; do + test -f "$m" || continue + test -n "$mark" && exit 1 + mark=$m +done + +test -f "$mark" || exit 1 + +snap_dir=${RSYNC_MODULE_PATH%/*} + +if test -f "$snap_dir/${mark##*/}"; then + # already have this snapshot + rm -f "$mark" + exit $? fi + +ts=${mark##*.} +rsync -aA --exclude=/.snapshot.\* --link-dest="$RSYNC_MODULE_PATH/" "$RSYNC_MODULE_PATH/" "$snap_dir/$ts/" || exit $? +mv "$mark" "$snap_dir/" || exit $? diff --git a/bin/snap.rsync.post b/bin/snap.rsync.post.zsh diff --git a/bin/snap.rsync.pre b/bin/snap.rsync.pre @@ -1,9 +1,25 @@ -#!/bin/zsh -env | grep RSYNC 1>&2 +#!/bin/sh +exec 1>&2 +env | grep RSYNC | sort | tr '\n' '\t'; echo set -x -# mkdir -p /tmp/snaprep/new || exit $? -[[ $RSYNC_MODULE_NAME != 'snaprep_new' ]] && exit 0 +case $RSYNC_MODULE_NAME in + (*.push) ;; + (*) exit 1;; +esac -f=( $RSYNC_MODULE_PATH/.snapshot.[0-9]*(N) ) -if (($#f)); then $0:h/post; fi +for m in $RSYNC_MODULE_PATH/.snapshot.[0-9]*; do + test -f "$m" || continue + if test -n "$erase"; then + rm -f "$m" || exit $? + elif test -n "$mark"; then + rm -f "$m" "$mark" || exit $? + erase=1 + fi + mark=$m +done + +test -n "$erase" && exit 0 + +test -f "$mark" && snap.rsync.post +exit 0 diff --git a/rsyncd.conf b/rsyncd.conf @@ -20,10 +20,10 @@ max verbosity = 2 path = /tmp/snaprep read only = yes -[snaprep_new] +[snaprep.push] path = /tmp/snaprep/new read only = no write only = yes refuse options = inplace - pre-xfer exec = /home/ccx/bzr/snaprep/pre - post-xfer exec = /home/ccx/bzr/snaprep/post + pre-xfer exec = /home/ccx/bzr/snaprep/bin/snap.rsync.pre + post-xfer exec = /home/ccx/bzr/snaprep/bin/snap.rsync.post