From: Hugo Villeneuve Date: Thu, 2 Apr 2026 17:57:00 +0000 (-0400) Subject: hv-rsync: improve diff output X-Git-Url: http://gitweb.hugovil.com/sitemap.xml?a=commitdiff_plain;h=2f86315df20bd49cb845471000ede7660856ae3a;p=hvutilities.git hv-rsync: improve diff output --- diff --git a/scripts/hv-rsync.sh b/scripts/hv-rsync.sh index 1f01802..4884582 100755 --- a/scripts/hv-rsync.sh +++ b/scripts/hv-rsync.sh @@ -4,6 +4,8 @@ PROG_NAME=$(basename $0) HVRSYNC_CONF=${HOME}/.hv-rsync.conf +RSYNC_DIFF_OPTS="-avun --itemize-changes --size-only --delete" + print_usage() { echo "${PROG_NAME} -- synchronisation serveur RSYNC" @@ -77,6 +79,25 @@ fi # files, modification times, groups, owners, and permissions. # -n: dry-run +delete_target="" + +rsync_itemize_parser() +{ + local stdin + + read -d '' -u 0 stdin + + # Show lines starting with >, <, c, or * (deletions), effectively + # hiding entries that were only checked but not changed: + # grep -E '^([<>c\*])' + printf "%s\n" "$stdin" | \ + grep -E '^([<>c\*])' | \ + sed -e "s/^\*deleting\s\+/[${delete_target} DEL] /" | \ + sed -e "s/^<[fLd][.cstpoaguax+]\{9\}/[SEND] /" | \ + sed -e "s/^>[fLd][.cstpoaguax+]\{9\}/[RECV] /" | \ + sed -e "s/^cd[.cstpoaguax+]\{9\}/[${delete_target} DIR]/" +} + for f in ${rsync_list}; do if [ x"${mode}" = x"diff" ]; then @@ -86,18 +107,17 @@ for f in ${rsync_list}; do fi echo "Diff (push) for folder ${RSYNC_REMOTE_DIR}/${f}:" - - rsync -avun --delete \ - "${RSYNC_LOCAL_DIR}/${f}/" \ + delete_target="REMOTE" + rsync ${RSYNC_DIFF_OPTS} "${RSYNC_LOCAL_DIR}/${f}/" \ ${RSYNC_USER}@${RSYNC_SERVER}:"${RSYNC_REMOTE_DIR}/${f}" | \ - grep "^deleting " + rsync_itemize_parser echo "Diff (pull) for folder ${RSYNC_REMOTE_DIR}/${f}:" + delete_target="LOCAL " + rsync ${RSYNC_DIFF_OPTS} ${RSYNC_USER}@${RSYNC_SERVER}:"${RSYNC_REMOTE_DIR}/${f}/" \ + "${RSYNC_LOCAL_DIR}/${f}" | \ + rsync_itemize_parser - rsync -avun --delete \ - ${RSYNC_USER}@${RSYNC_SERVER}:"${RSYNC_REMOTE_DIR}/${f}/" \ - "${RSYNC_LOCAL_DIR}/${f}" | \ - grep "^deleting " elif [ x"${mode}" = x"pull" ]; then echo "RSYNC for folder ${RSYNC_REMOTE_DIR}/${f}:" mkdir -p ${RSYNC_LOCAL_DIR}/${f}