blob: 35b02da958a62243ac36d0d1286e4c4058faa87b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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"
|