From 0eae9c3f895ddf187e3807aa76ae3400379a2ad1 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 10 Sep 2018 09:42:28 +0200 Subject: lib/common-functions: failsafe_rsync() new --- lib/common-functions | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/common-functions b/lib/common-functions index 6e0892d..7776725 100755 --- a/lib/common-functions +++ b/lib/common-functions @@ -225,12 +225,12 @@ remove_old_package_versions() { # repo-remove packages while read -r arch repo pkgname; do mkdir "${tmp_dir}/transit" - ${master_mirror_rsync_command} \ + failsafe_rsync \ "${master_mirror_rsync_directory}/${arch}/${repo}/${repo}.db."* \ "${master_mirror_rsync_directory}/${arch}/${repo}/${repo}.files."* \ "${tmp_dir}/transit/" repo-remove "${tmp_dir}/transit/${repo}.db.tar.gz" "${pkgname}" - ${master_mirror_rsync_command} \ + failsafe_rsync \ "${tmp_dir}/transit/${repo}.db."* \ "${tmp_dir}/transit/${repo}.files."* \ "${master_mirror_rsync_directory}/${arch}/${repo}/" @@ -709,7 +709,7 @@ trigger_mirror_refreshs() { tmp_file=$(mktemp "tmp.common-functions.trigger_mirror_refreshs.XXXXXXXXXX" --tmpdir) date '+%s' > \ "${tmp_file}" - ${master_mirror_rsync_command} \ + failsafe_rsync \ "${tmp_file}" \ "${master_mirror_rsync_directory}/lastupdate" rm "${tmp_file}" @@ -882,3 +882,26 @@ failsafe_sftp() { ) || \ return $? } + +# failsafe_rsync +# execute rsync with the given parameters on the master mirror, retrying +# if unsuccessful +# caveats: +# - output might be garbled +# - error code will be projected into {0,1} +failsafe_rsync() { + local trial_counter + + trial_counter=20 + if ${master_mirror_rsync_command} "$@"; then + return 0 + fi + while [ ${trial_counter} -gt 0 ]; do + wait_some_time 30 + if ${master_mirror_rsync_command} "$@"; then + return 0 + fi + trial_counter=$((trial_counter-1)) + done + return 1 +} -- cgit v1.2.3-54-g00ecf