diff options
author | Esteban Carnevale <alfplayer@mailoo.org> | 2014-12-27 14:18:06 -0300 |
---|---|---|
committer | Esteban Carnevale <alfplayer@mailoo.org> | 2014-12-27 14:18:06 -0300 |
commit | 44ca21f76da732038a6e9ff7353a12846c58aa14 (patch) | |
tree | 56af6f41582803326f54899e84a2a6b02ad47454 | |
parent | 809ab504d593a09c7752a966a10edac0d5f9326a (diff) |
parabola-mirror: Remove logging and mail sending
To simplify the script. Also, rsync output now
does not use --progress by default so the output
can be logged and mailed by a wrapper.
Configuration variable "terminal" can be set to
1 to enable --progress.
-rwxr-xr-x | parabola-mirror | 54 |
1 files changed, 4 insertions, 50 deletions
diff --git a/parabola-mirror b/parabola-mirror index de9893b..d8a607a 100755 --- a/parabola-mirror +++ b/parabola-mirror @@ -9,9 +9,6 @@ set -e script_filename="$(basename "$0")" -# Create temporary log file -log_tmp="$(mktemp -p /var/tmp)" - # Default configuration values. # They can be overridden by setting the variables in the calling environment. # 1 to set, 0 to unset @@ -19,65 +16,32 @@ log_tmp="$(mktemp -p /var/tmp)" : ${base_dir:=/srv/http} : ${parabola_dir:=${base_dir}/parabola} : ${oldest_version:=10} # snapshots older than this one will be deleted (see also no_delete above) -: ${log_file:=${script_filename}.log} -#: ${mail_to:=your@mail.com} # comment out to disable #: ${date_exclude:=2014.06.19} # disable running this script this date (see next line) : ${forcerun:=0} # force running on excluded date -: ${terminal:=1} # outputs to stdout using rsync --progress (and logs to a file) +#: ${terminal:=1} # outputs to stdout using rsync --progress (and logs to a file) : ${no_delete:=0} # disable deletion of oldest snapshots #: ${TZ:=UTC} # set time zone export TZ -# Lock with flock (provided by util-linux), save to log file and send email on exit +# Lock with flock (provided by util-linux) LOCKFILE="/var/lock/${script_filename}" LOCKFD=99 _lock() { flock -$1 $LOCKFD; } -# Wait until there is no process writing to ${log_tmp} -# Waiting can be necessary if command groups are not executed until the end -_wait_log_tmp() { - if [[ -e "${log_tmp}" ]] ; then - while fuser "${log_tmp}" > /dev/null ; do - sleep 0.2 - done - fi -} - _no_more_locking() { set +e # Save exit status es=$? - _wait_log_tmp - cat "${log_tmp}" >> "${log_file}" - - if [[ $? == 0 ]] ; then - log_written=1 - else - echo "=> ERROR: Failed to write to log file: ${log_file}" >&2 - fi - if [[ -e ${parabola_dir}.tmp ]] ; then echo "=> WARNING: Directory with partial transfer ${LOCAL}.tmp remains in file system" fi - if [[ ${mail_to} ]] ; then - echo "=> Sending output to ${mail_to}" - mail -s "[$(hostname)] ${script_filename}" "${mail_to}" < "${log_tmp}" - fi - - if [[ ${log_written} == 1 ]] ; then - rm -f "${log_tmp}" - fi - if [[ $es != 0 ]] ; then - echo "=> WARNING: Unsuccessful script termination. Exit status: $es" - if [[ ${mail_to} ]] ; then - echo "=> Sending error notification to ${mail_to}" - mail -s "[$(hostname)] ${script_filename} failed. See logged output." "${mail_to}" < /dev/null + echo "=> ERROR: Unsuccessful script termination. Exit status: $es" fi fi @@ -100,7 +64,6 @@ date="$(date +%Y.%m.%d)" current="${parabola_dir}-${date}" local_useful=0 -{ if [[ ${date_exclude} && ${forcerun} != 1 ]] ; then if [[ $DATE == ${date_exclude} ]] ; then @@ -139,13 +102,8 @@ else cp -al "${last_path}" "${parabola_dir}".tmp fi -} &> >(tee -a "${log_tmp}") -_wait_log_tmp - -rsync "${repo}"/ -rtvlH ${terminal:+--progress} --log-file="${log_tmp}" --safe-links --delete --link-dest="$base_dir"/archlinux/ --link-dest="$parabola_dir" "$parabola_dir".tmp - -{ +rsync "${repo}"/ -rtvlH ${terminal:+--progress} --safe-links --delete --link-dest="$base_dir"/archlinux/ --link-dest="$parabola_dir" "$parabola_dir".tmp cd "$base_dir" @@ -177,7 +135,3 @@ echo "=> Disk space report" df -h / echo "=> ${script_filename} finished successfully. Finish time: $(date --rfc-3339=seconds)" - -} &> >(tee -a "${log_tmp}") - -_wait_log_tmp |