[Mageia-dev] Distrib-coffee big failure of the century

Barry Jackson zen25000 at zen.co.uk
Fri Nov 2 00:41:27 CET 2012


On 01/11/12 20:51, Barry Jackson wrote:
>
> See how it goes :)
>
Last update - honest - added proper file lock as the existing method was 
flakey - it's finished and I'm leaving it alone now :)
Attached and also here:-
http://paste.kde.org/588158/12522135/

-------------- next part --------------
#!/bin/bash
# ~/cronsync by barjac
# Run with e.g. crontab:- 30 * * * *	$HOME/cronsync
# Set using crontab -e
###################
# List of mirrors in preference order to use:-
mymirrors=( \
"rsync://distrib-coffee.ipsl.jussieu.fr:/pub/linux/Mageia/distrib" \
"rsync://ftp.LinuxCabal.org/Mageia/distrib" \
"rsync://fr2.rpmfind.net/linux/mageia/distrib" \
"rsync://ftp.acc.umu.se/mirror/mageia/distrib" \
"rsync://mirrors.kernel.org:/mirrors/mageia/distrib" \
"rsync://mageia.c3sl.ufpr.br/mageia/distrib" \
)
# Set limit for loss of # of files on server before it is skipped
allowdropfiles=100
###################
# Personal config:-
myexcludes="--exclude=debug --exclude=SRPMS --exclude=barjac"
mydestination="/zmrepo/pub/linux/Mageia/"
###################

# Set minimum files for first run only
[[ -f .cronsync ]] || echo "140000" > $HOME/.cronsync
# Get minimum file count for mirror (set at allowdropfiles files less than the last actual file count)
minfiles=$(cat .cronsync)
((actualfiles = $minfiles + $allowdropfiles))

# Function to output formatted date
dte()
{
echo -n $(date +%d/%m/%Y-%H:%M)
}

# Check a mirror
chk_mirror()
{
echo "Checking $1 ..."
rsync -rlptgoDhHSn \
--stats \
--delete-after \
--delete-excluded \
--protect-args \
$myexcludes \
"$1" \
"$mydestination" > $lockdir/cronsync_tmp_output
status=$?
files=$(cat $lockdir/cronsync_tmp_output | grep "Number of files:" | cut -d' ' -f4 )
[[ $files -lt $minfiles ]] && echo "$(dte): Only $files/$actualfiles files in $1" | tee -a $HOME/cronsync_error.log
[[ $status > 0 ]] && echo "$(dte): Error: $status while checking $1" | tee -a $HOME/cronsync_error.log
([[ $status = 0 ]] && [[ $files -gt $minfiles ]]) || return 1
# Save new minimum file count
((minfiles = $files - $allowdropfiles))
echo $minfiles > $HOME/.cronsync
return 0
}

# Loop through mirror list checking until one succeeds
find_good_mirror()
{
for mirr in ${mymirrors[@]}; do
chk_mirror $mirr && { echo "Found good mirror - $mirr"; return 0; }
done
echo "$(dte): Can't find a good mirror - aborting" | tee -a $HOME/cronsync_error.log
return 1
}
################### Main routine starts here
# Avoid running two instances concurrently
lockdir=/tmp/cronsync.lock
if mkdir "$lockdir"; then
trap 'rm -rf "$lockdir"' 0

# Find a good mirror from the list (with files in it)
find_good_mirror || exit 1

# Live run with --max-delete set to 1000 just in case ;)
echo "Syncing from $mirr ..."
rsync -rlptgoDhHS \
--progress \
--stats \
--delete-after \
--max-delete=1000 \
--delete-excluded \
--protect-args \
$myexcludes \
"$mirr" \
"$mydestination" | tee $HOME/cronsync_last.log
status=${PIPESTATUS[0]}
[[ $status = 0 ]] || { echo "$(dte): Live run rsync error: $status" >> $HOME/cronsync_error.log; exit 1; }
echo "Update complete"
else
echo "$(dte): cronsync already running or stale lock - skipping update - check /tmp/cronsync.lock" >> $HOME/cronsync_error.log
exit 0
fi
################### End of cronsync







More information about the Mageia-dev mailing list