apt-mirror scripts that can maintain consistent mirror snapshots. https://lerlacher.de/posts/2017-01-25-working-ubuntu-mirror.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "apt-mirror start: $(date)" | |
args=$(getopt -l "initial,config:" -o "i,c:" -- "$@") | |
eval set -- "$args" | |
initial=0 | |
config=/etc/apt/mirror.list | |
while [ $# -ge 1 ]; do | |
case "$1" in | |
--) | |
# No more options left. | |
shift | |
break | |
;; | |
-i|--initial) | |
initial=1 | |
shift | |
;; | |
-c|--config) | |
config="$2" | |
shift | |
;; | |
esac | |
shift | |
done | |
if pgrep apt-mirror >/dev/null; then | |
killall apt-mirror | |
echo "Killed running apt-mirror" | |
# echo "Saving state..." | |
# name="dist-bak-$(date +%s)" | |
# mkdir -p /srv/ubuntumirror/backups/$name | |
# cp -r /srv/ubuntumirror/mirror/de.archive.ubuntu.com/ubuntu/dists /srv/ubuntumirror/backups/$name | |
# echo "Done, old state saved to /srv/ubuntumirror/backups/$name" | |
fi | |
if [[ $initial == 1 ]]; then | |
echo "Initial run, removing SUCCESS sentinel" | |
[ -e /srv/ubuntumirror/SUCCESS ] && rm /srv/ubuntumirror/SUCCESS | |
fi | |
echo "Running apt-mirror from $config" | |
echo "Running apt-mirror from $config at $(date)" >>/var/log/apt/mirror.cronstderr.log | |
APTMIRROUT=$(/usr/local/bin/apt-mirror $config 2>>/var/log/apt/mirror.cronstderr.log | tee -a /var/log/apt/mirror.cron.log) | |
# create snapshot | |
SNAPSHOTLOC="/srv/ubuntumirror/.zfs/snapshot/$(date +%s)" | |
echo "Creating snapshot in $SNAPSHOTLOC" | |
mkdir $SNAPSHOTLOC | |
echo "apt-mirror finish: $(date)" | |
if [ -e /srv/ubuntumirror/SUCCESS ] | |
then | |
echo "Success - pointing webserver at snapshot" | |
rm /var/www/ubuntu | |
ln -s $SNAPSHOTLOC/mirror/de.archive.ubuntu.com/ubuntu /var/www/ubuntu | |
else | |
echo "Fail - check logs" >&2 | |
echo "$APTMIRROUT" >&2 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
basedir=/srv/ubuntumirror | |
ret=0 | |
newfiles=$(wc -l $basedir/var/NEW | grep -o '^[0-9]\+') | |
if [[ "0" == $newfiles && "$1" != "force" ]] | |
then | |
echo "No new files" | |
else | |
echo "Checking Package list files" | |
for i in $basedir/mirror/de.archive.ubuntu.com/ubuntu/dists/*; do | |
( | |
cd $i | |
pmis=$(tail -n +11 Release | egrep '^ [a-z0-9]{32} ' | grep -v -e '-\(powerpc\|sparc\|ia64\|armel\|armhf\|ppc64el\|arm64\|s390x\)\(/\|\.\|$\)' -e '\(Contents\|Components\)-[^.]\+\(\.yml\)\?$' -e '\.tar$' -e '/debian-installer/' -e '/i18n/\(Translation\|Index\)' | awk '{print $1" "$3}' | md5sum -c --quiet 2>&1 ) | |
pmisfiles=$(echo "$pmis" | sed '/^$/d' | wc -l) | |
if [[ "0" == $pmisfiles ]] | |
then | |
echo "All package list files good in $(basename $i)" | |
exit 0 | |
else | |
echo "$pmisfiles Bad package list files in $(basename $i):" | |
echo "$pmis" | |
exit 1 | |
fi | |
) || ret=1 | |
done | |
cd $basedir/mirror | |
newfiles=$(wc -l $basedir/var/NEW | grep -o '^[0-9]\+') | |
if [[ "0" == $newfiles ]] | |
then | |
echo "No new package files" | |
else | |
mismatch=$(cut -b"8-" $basedir/var/NEW | xargs -I '{}' -n 1 grep -F "{}" $basedir/var/MD5 | md5sum --quiet -c 2>&1 ) | |
#echo "$mismatch" | |
mismatchfiles=$(echo "$mismatch" | sed '/^$/d' | wc -l) | |
if [[ "0" == $mismatchfiles ]] | |
then | |
echo "All $newfiles new package files good" | |
else | |
echo "$newfiles new package files, but $mismatchfiles bad files:" | |
echo "$mismatch" | |
ret=1 | |
fi | |
fi | |
fi | |
if [[ "0" == $ret ]]; then | |
touch /srv/ubuntumirror/SUCCESS | |
fi | |
echo "postmirror done at $(date)" | |
exit $ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment