1
1
mirror of https://gitlab.archlinux.org/archlinux/infrastructure.git synced 2025-01-18 08:06:16 +01:00
infrastructure/roles/arch32_mirror/templates/syncrepo_arch32
Bartłomiej Piotrowski ce4d17109c Revert "arch32_mirror: rely solely on lastupdate"
This reverts commit a2c61b56ad5b99e3a32cf0ba03342bac1fc63e93.
2017-11-15 21:29:41 +01:00

64 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# This is a simple mirroring script. To save bandwidth it first checks a
# timestamp via HTTP and only runs rsync when the timestamp differs from the
# local copy. As of 2016, a single rsync run without changes transfers roughly
# 6MiB of data which adds up to roughly 250GiB of traffic per month when rsync
# is run every minute. Performing a simple check via HTTP first can thus save a
# lot of traffic.
target="{{ arch32_mirror_dir }}"
tmp="/srv/syncrepo_arch32-tmp"
lock="/var/lock/syncrepo_arch32.lck"
# NOTE: You'll probably want to change this or set it to 0 to disable the limit
# The default unit is KiB (see man rsync /--bwlimit for more)
bwlimit=0
# NOTE: Most people reading this very likely need to change this since
# rsync.archlinux.org requires you to be a tier 1 mirror
source='{{ arch32_mirror_source }}'
lastupdate_url='{{ arch32_mirror_lastupdate }}'
#### END CONFIG
[ ! -d "${target}" ] && mkdir -p "${target}"
[ ! -d "${tmp}" ] && mkdir -p "${tmp}"
exec 9>"${lock}"
flock -n 9 || exit
rsync_cmd() {
local -a cmd=(rsync -rtlH --safe-links --delete-after ${VERBOSE} "--timeout=600" "--contimeout=60" -p \
--delay-updates --no-motd "--temp-dir=${tmp}")
if stty &>/dev/null; then
cmd+=(-h -v --progress)
else
cmd+=("--info=name1")
fi
if ((bwlimit>0)); then
cmd+=("--bwlimit=$bwlimit")
fi
"${cmd[@]}" "$@"
}
# if we are called without a tty (cronjob) only run when there are changes
if ! tty -s && [[ -f "$target/lastupdate" ]] && diff -b <(curl -s "$lastupdate_url") "$target/lastupdate" >/dev/null; then
# keep lastsync file in sync for statistics generated by the Arch Linux website
rsync_cmd "$source/lastsync" "$target/lastsync"
exit 0
fi
rsync_cmd \
--exclude='*.links.tar.gz*' \
--exclude='/other' \
--exclude='/sources' \
"${source}" \
"${target}"
#echo "Last sync was $(date -d @$(cat ${target}/lastsync))"