mirror of
https://github.com/phfroidmont/self-hosting.git
synced 2025-12-25 13:46:59 +01:00
Sync arch mirror every 6 hour
This commit is contained in:
parent
a5785e21ed
commit
1e93c4ae3d
2 changed files with 94 additions and 0 deletions
80
roles/arch-mirror-docker/files/syncArchRepo.sh
Executable file
80
roles/arch-mirror-docker/files/syncArchRepo.sh
Executable file
|
|
@ -0,0 +1,80 @@
|
||||||
|
#!/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.
|
||||||
|
|
||||||
|
# Directory where the repo is stored locally. Example: /srv/repo
|
||||||
|
target="/srv/repo"
|
||||||
|
|
||||||
|
# Directory where files are downloaded to before being moved in place.
|
||||||
|
# This should be on the same filesystem as $target, but not a subdirectory of $target.
|
||||||
|
# Example: /srv/tmp
|
||||||
|
tmp="/srv/tmp"
|
||||||
|
|
||||||
|
# Lockfile path
|
||||||
|
lock="/home/claude/.lock/syncrepo.lck"
|
||||||
|
|
||||||
|
# If you want to limit the bandwidth used by rsync set this.
|
||||||
|
# Use 0 to disable the limit.
|
||||||
|
# The default unit is KiB (see man rsync /--bwlimit for more)
|
||||||
|
bwlimit=0
|
||||||
|
|
||||||
|
# The source URL of the mirror you want to sync from.
|
||||||
|
# If you are a tier 1 mirror use rsync.archlinux.org, for example like this:
|
||||||
|
# rsync://rsync.archlinux.org/ftp_tier1
|
||||||
|
# Otherwise chose a tier 1 mirror from this list and use its rsync URL:
|
||||||
|
# https://www.archlinux.org/mirrors/
|
||||||
|
source_url='rsync://mirror.f4st.host/archlinux/'
|
||||||
|
|
||||||
|
# An HTTP(S) URL pointing to the 'lastupdate' file on your chosen mirror.
|
||||||
|
# If you are a tier 1 mirror use: http://rsync.archlinux.org/lastupdate
|
||||||
|
# Otherwise use the HTTP(S) URL from your chosen mirror.
|
||||||
|
lastupdate_url='https://mirror2.f4st.host/archlinux/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+=(--quiet)
|
||||||
|
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 -Ls "$lastupdate_url") "$target/lastupdate" >/dev/null; then
|
||||||
|
# keep lastsync file in sync for statistics generated by the Arch Linux website
|
||||||
|
rsync_cmd "$source_url/lastsync" "$target/lastsync"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
rsync_cmd \
|
||||||
|
--exclude='*.links.tar.gz*' \
|
||||||
|
--exclude='/other' \
|
||||||
|
--exclude='/sources' \
|
||||||
|
--exclude='/iso' \
|
||||||
|
"${source_url}" \
|
||||||
|
"${target}"
|
||||||
|
|
||||||
|
#echo "Last sync was $(date -d @$(cat ${target}/lastsync))"
|
||||||
|
|
||||||
|
|
@ -1,4 +1,18 @@
|
||||||
---
|
---
|
||||||
|
- name: Copy mirror sync script
|
||||||
|
copy:
|
||||||
|
src: syncArchRepo.sh
|
||||||
|
dest: /home/claude/syncArchRepo.sh
|
||||||
|
mode: 0700
|
||||||
|
owner: claude
|
||||||
|
- name: Create mirror sync cron job
|
||||||
|
cron:
|
||||||
|
name: arch mirror sync
|
||||||
|
state: present
|
||||||
|
minute: 0
|
||||||
|
hour: "*/6"
|
||||||
|
job: "/home/claude/syncArchRepo.sh"
|
||||||
|
user: claude
|
||||||
- name: Copy Arch Linux mirror config
|
- name: Copy Arch Linux mirror config
|
||||||
copy: src=arch-mirror dest={{docker_compose_files_folder}}
|
copy: src=arch-mirror dest={{docker_compose_files_folder}}
|
||||||
- name: Start Arch mirror project
|
- name: Start Arch mirror project
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue