#!/bin/sh
TARGETS="<%= @targets.flatten.join(' ') -%>"

if [ -z "$TARGETS"]; then
  logger -t mirrorer empty target received for govuk mirror
fi

START_UPLOAD=$(($(date +%s%N)/1000000))

for TARGET in $TARGETS; do
  logger -t mirrorer Started uploading to $TARGET
  rsync -rLptgoD -z --delete /var/lib/govuk_mirror/current/. \
               $TARGET:/srv/mirror_data/www-origin
  EXITCODE=$?
  if [ "$EXITCODE" != "0" ]; then
     logger -p user.crit -t mirrorer Uploading mirror $TARGET failed with exit code: $EXITCODE
  fi
  logger -t mirrorer Finished uploading to mirror $TARGET
done

STOP_UPLOAD=$(($(date +%s%N)/1000000))
DURATION_UPLOAD=$(expr $STOP_UPLOAD - $START_UPLOAD)
echo "govuk.app.mirrorer.upload_duration:$DURATION_UPLOAD|ms" | nc -w 1 -u localhost 8125

#!/bin/sh
TARGETS="<%= @targets.flatten.join(' ') -%>"

if [ -z "$TARGETS"]; then
  logger -t mirrorer empty target received for govuk mirror
fi

START_UPLOAD=$(($(date +%s%N)/1000000))

for TARGET in $TARGETS; do
  logger -t mirrorer Started uploading to $TARGET
  rsync -rLptgoD -z /var/lib/govuk_mirror/current/. \
               $TARGET:/srv/mirror_data/www-origin
  EXITCODE=$?
  if [ "$EXITCODE" != "0" ]; then
     logger -p user.crit -t mirrorer Uploading mirror $TARGET failed with exit code: $EXITCODE
  fi
  logger -t mirrorer Finished uploading to mirror $TARGET
done

STOP_UPLOAD=$(($(date +%s%N)/1000000))
DURATION_UPLOAD=$(expr $STOP_UPLOAD - $START_UPLOAD)
echo "govuk.app.mirrorer.upload_duration:$DURATION_UPLOAD|ms" | nc -w 1 -u localhost 8125

Remove the `--delete` flag for rsync
Remove the `--delete` flag for rsync

Prevent `rsync(1)` from deleting content on the remote machine when it
has been deleted locally.

This is primarily to prevent rsync from deleting the majority of the
content on the remote mirrors if the GOV.UK Crawler Worker has not yet
completed crawling the whole site.
