diff options
Diffstat (limited to 'hbsdmirror-sync.sh')
-rwxr-xr-x | hbsdmirror-sync.sh | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/hbsdmirror-sync.sh b/hbsdmirror-sync.sh new file mode 100755 index 0000000..c241883 --- /dev/null +++ b/hbsdmirror-sync.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ====== CONFIG ====== +# Pick a nearby Tier-1. Examples (use ONE): +# rsync://mirror.csclub.uwaterloo.ca/archlinux/ +# rsync://mirror.constant.com/archlinux/ +UPSTREAM="${UPSTREAM:-rsync://rsync.hardenedbsd.org/all/}" + +# Local paths +LIVE="${LIVE:-/brimstone2/mirror/hardenedbsd}" # served path (symlink target) +STAGE="${STAGE:-/brimstone3/mirror-stage/hbsd}" # staging path +LOGDIR="${LOGDIR:-/var/log/mirrors}" +LOCK="${LOCK:-/var/log/archmirror.lock}" + +# rsync knobs +RSYNC_OPTS=( + -rtlH --safe-links + --delete-delay --delay-updates + --partial --partial-dir=.rsync-partial + --timeout=600 --contimeout=60 +) + +# Niceness (be kind to disks) +IONICE=(ionice -c2 -n7) +NICE=(nice -n 15) + +mkdir -p "$STAGE" "$LIVE" "$LOGDIR" +exec 9>"$LOCK" +flock -n 9 || { echo "[$(date -Is)] another archmirror-sync is running, exiting"; exit 0; } + +log() { echo "[$(date -Is)] $*"; } +log "starting sync from $UPSTREAM" + +# First pass +"${IONICE[@]}" "${NICE[@]}" rsync "${RSYNC_OPTS[@]}" \ + "$UPSTREAM" "$STAGE" | tee -a "$LOGDIR/arch-sync.log" + +# Quick second pass to catch files updated mid-run +"${IONICE[@]}" "${NICE[@]}" rsync "${RSYNC_OPTS[@]}" \ + "$UPSTREAM" "$STAGE" | tee -a "$LOGDIR/arch-sync.log" + +# Atomic flip: make LIVE point at STAGE (symlink strategy) +# If LIVE is a directory you want to replace, serve via a symlink path like /srv/mirror/arch -> /srv/mirror-stage/arch +ln -sfn "$STAGE" "$LIVE" + +# Optional: write a local "lastsync" like Arch does, helps some clients +date -u +%s > "$LIVE/lastsync" + +log "sync complete; flipped LIVE -> $STAGE" |