From 483cfee90cd9a13d096a039ee516d620b15f9980 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 27 Jul 2009 09:37:50 +0200 Subject: [PATCH] Reorder: All checks being done in the same place All configurations are checked in the same place Signed-off-by: Nico Schottelius --- ccollect.sh | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/ccollect.sh b/ccollect.sh index c07852a..90862b1 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -278,13 +278,14 @@ while [ "${i}" -lt "${no_sources}" ]; do fi # - # Read Configuration + # Read / create configuration # backup="${CSOURCES}/${name}" c_source="${backup}/source" c_dest="${backup}/destination" c_pre_exec="${backup}/pre_exec" c_post_exec="${backup}/post_exec" + c_marker=".ccollect-marker" for opt in exclude verbose very_verbose rsync_options summary delete_incomplete \ remote_host rsync_failure_codes mtime quiet_if_down ; do if [ -f "${backup}/${opt}" -o -f "${backup}/no_${opt}" ]; then @@ -301,11 +302,6 @@ while [ "${i}" -lt "${no_sources}" ]; do TSORT="t" fi - # - # Marking backups: If we abort it's not removed => Backup is broken - # - c_marker=".ccollect-marker" - # # First execute pre_exec, which may generate destination or other parameters # @@ -320,7 +316,7 @@ while [ "${i}" -lt "${no_sources}" ]; do fi # - # Source checks + # Source configuration checks # if [ ! -f "${c_source}" ]; then _exit_err "Source description \"${c_source}\" is not a file. Skipping." @@ -331,16 +327,6 @@ while [ "${i}" -lt "${no_sources}" ]; do fi fi - # - # Verify source is up and accepting connections before deleting any old backups - # - if ! rsync "${source}" >/dev/null 2>"${TMP}" ; then - if [ ! -f "${c_quiet_if_down}" ]; then - cat "${TMP}" - fi - _exit_err "Source ${source} is not readable. Skipping." - fi - # # Destination is a path # @@ -368,23 +354,18 @@ while [ "${i}" -lt "${no_sources}" ]; do fi export remote_host - # - # check for existence / use real name - # - ( pcmd cd "$ddir" ) || _exit_err "Cannot change to ${ddir}. Skipping." - # # Parameters: ccollect defaults, configuration options, user options # # - # rsync standard options + # Rsync standard options # set -- "$@" "--archive" "--delete" "--numeric-ids" "--relative" \ "--delete-excluded" "--sparse" # - # exclude list + # Exclude list # if [ -f "${c_exclude}" ]; then set -- "$@" "--exclude-from=${c_exclude}" @@ -409,7 +390,7 @@ while [ "${i}" -lt "${no_sources}" ]; do fi # - # extra options for rsync provided by the user + # Extra options for rsync provided by the user # if [ -f "${c_rsync_options}" ]; then while read line; do @@ -418,7 +399,22 @@ while [ "${i}" -lt "${no_sources}" ]; do fi # - # Check for incomplete backups + # Check: source is up and accepting connections (before deleting old backups!) + # + if ! rsync "${source}" >/dev/null 2>"${TMP}" ; then + if [ ! -f "${c_quiet_if_down}" ]; then + cat "${TMP}" + fi + _exit_err "Source ${source} is not readable. Skipping." + fi + + # + # Check: destination exists? + # + ( pcmd cd "${ddir}" ) || _exit_err "Cannot change to ${ddir}. Skipping." + + # + # Check: incomplete backups? # pcmd ls -1 "${ddir}/"*".${c_marker}" 2>/dev/null | while read marker; do incomplete="$(echo ${marker} | sed "s/\\.${c_marker}\$//")"