diff options
author | doc <doc@filenotfound.org> | 2025-09-14 22:13:41 +0000 |
---|---|---|
committer | doc <doc@filenotfound.org> | 2025-09-14 22:13:41 +0000 |
commit | 13eb2d51c7284472efabc278bf9b7ec0b8575e47 (patch) | |
tree | 9f0ea15fdc908a2afe4d315beb112fe9545db02e /archmirror-sync.sh |
Diffstat (limited to 'archmirror-sync.sh')
-rwxr-xr-x | archmirror-sync.sh | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/archmirror-sync.sh b/archmirror-sync.sh new file mode 100755 index 0000000..35b02da --- /dev/null +++ b/archmirror-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://mirror.csclub.uwaterloo.ca/archlinux/}" + +# Local paths +LIVE="${LIVE:-/brimstone1/mirror/archlinux}" # served path (symlink target) +STAGE="${STAGE:-/brimstone3/mirror-stage/archlinux}" # 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" |