improved -n, added ha-diff
authorHeiko Schlittermann <hs@schlittermann.de>
Thu, 13 Aug 2009 23:39:27 +0200
changeset 26 673369649d1e
parent 25 ad6cef118983
child 27 649e1124e01b
improved -n, added ha-diff
Makefile
debian/changelog
ha-diff
ha-sync
--- a/Makefile	Tue Aug 11 20:22:58 2009 +0000
+++ b/Makefile	Thu Aug 13 23:39:27 2009 +0200
@@ -1,4 +1,4 @@
-SCRIPTS = ha-config ha-hostname ha-sync
+SCRIPTS = ha-config ha-hostname ha-sync ha-diff
 
 all:
 	chmod	a+rx $(SCRIPTS)
--- a/debian/changelog	Tue Aug 11 20:22:58 2009 +0000
+++ b/debian/changelog	Thu Aug 13 23:39:27 2009 +0200
@@ -1,3 +1,10 @@
+ha-sync (0.15) stable; urgency=low
+
+  * improved ā€ž-nā€ to show --itemized-changes
+  * added ha-diff (experimental)
+
+ -- Heiko Schlittermann <hs@schlittermann.de>  Thu, 13 Aug 2009 23:38:33 +0200
+
 ha-sync (0.14-1) stable; urgency=low
 
   * Path updated (tail not found)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ha-diff	Thu Aug 13 23:39:27 2009 +0200
@@ -0,0 +1,17 @@
+#! /usr/bin/perl
+# ha-diff [diff-options] <other> file
+use strict;
+use warnings;
+use Cwd qw(abs_path);
+
+die "bad usage" if @ARGV < 2;
+
+my $file = pop @ARGV;
+my $other = pop @ARGV;
+
+$file = abs_path($file) if not $file =~ /^\//;
+push @ARGV, "-u" if (not @ARGV);
+
+system qq{/bin/bash -c "diff @ARGV --label other <(ssh $other cat '$file') '$file'"};
+system qq{/bin/bash -c "diff @ARGV --label other --label local <(ssh $other stat '$file') <(stat '$file')"}
+	if $? == 0;
--- a/ha-sync	Tue Aug 11 20:22:58 2009 +0000
+++ b/ha-sync	Thu Aug 13 23:39:27 2009 +0200
@@ -1,11 +1,7 @@
 #! /bin/bash
-# (c) 2006 Heiko Schlittermann <hs@schlittermann.de>
-# $Id$
-# $URL$
+CONFIG=/etc/ha-sync/ha-sync.conf
+source $CONFIG
 
-CONFIG=/etc/ha-sync/ha-sync.conf
-
-source $CONFIG
 test "$NODE_A" \
 	&& test "$NODE_B" \
 	&& test "$FILESYSTEMS" \
@@ -20,6 +16,16 @@
 	exit 2
 }
 
+# check rsync version
+rsync --help | grep -qe '--acls' || {
+	echo "$0: rsync does not support '--acls'" >&2
+	exit
+}
+
+rsync --help | grep -qe '--itemize-changes' || {
+	echo "$0: rsync does not support '--itemize-changes'" >&2
+	exit
+}
 
 NODES="$NODE_A $NODE_B"
 
@@ -44,15 +50,30 @@
 	echo $NODES | tr ' ' '\n' | grep -v `hostname`; 
 }
 
-# extra exclude list
+# exclude list
 # we cannot sync the dirs under maintainance of drbdlinks
 # on any of our nodes...
-extra=`tempfile`
-trap "rm -f $extra" EXIT
-echo $extra >$extra	# and exclude it!
+exclude=`tempfile`
+trap "rm -f $exclude" EXIT
+echo $exclude >$exclude	# and exclude it!
+
+OTHER=`other`
+while read; do
+    if test "${REPLY:0:1}" = '`'; then
+	REPLY=${REPLY#?}
+	REPLY=${REPLY%?}
+	{ 
+	    $REPLY 
+	    ssh -i "$SSHID" $OTHER "$REPLY" </dev/null
+	} | sort -u
+    else 
+	echo "$REPLY"
+    fi
+done </etc/ha-sync/exclude >>$exclude
+
 
 command -v drbdlinks >/dev/null && {
-    drbdlinks list | sed 's/[[:space:]].*//' >>$extra
+    drbdlinks list | sed 's/[[:space:]].*//' >>$exclude
 }
 
 cd / || exit 1
@@ -63,32 +84,19 @@
 	test "`df -m \"$FS\" | awk 'NR == 2 {print $3 < 100}'`" = 1 \
 		&& extraopt=-c
 
-	${opt_debug+echo} rsync ${opt_dry+-n} \
+	${opt_debug+echo} rsync ${opt_dry+-ni} \
 		$extraopt \
-		--exclude-from $extra \
-		--exclude-from /etc/ha-sync/exclude \
-		--del -Ravx .$FS `other`:/
-
-	# if there's .acl in the top level dir, we have to apply these
-	# acl!
-	#find .$FS -name .acl -print0 | while read -d '' ACL; do
-	#	dir=$(dirname "$ACL")
-	#	acl=$(basename "$ACL")
-	#	cmd="cd '/$dir' && setfacl --restore '$acl'"
-	#	echo "Processing $ACL"
-	#	${opt_debug+echo} ${opt_dry+echo} ssh `other` "$cmd"
-	#done
-
-	echo "processing acl..."
-	find ${FS##/} -xdev -depth -not -type l -print0 | xargs -0 getfacl --skip-base \
-		| ssh -i $SSHID `other` 'cd / && setfacl --restore -'
-
+		--exclude-from $exclude \
+		--del --acls -Ravx .$FS `other`:/
 
 done
 
+
 # we do not sync the kernel anymore!
 #test "$opt_dry" || ${opt_debug+echo} ssh -i $SSHID `other` update-grub
 
 test "$opt_dry" \
     || ${opt_debug+echo} \
        ssh -i $SSHID `other` "run-parts /etc/ha-sync/scripts"
+
+# vim:sts=4 sw=4 aw ai sm: