From a030a989826e398dcc432b62384fbaeb3c57cc3a Mon Sep 17 00:00:00 2001 From: John Lawless Date: Mon, 18 May 2009 22:22:15 -0700 Subject: [PATCH 01/13] First, I added the following before any old backup gets deleted: > # Verify source is up and accepting connections before deleting any old backups > rsync "$source" >/dev/null || _exit_err "Source ${source} is not readable. Skipping." I think that this quick test is a much better than, say, pinging the source in a pre-exec script: this tests not only that the source is up and connected to the net, it also verifies (1) that ssh is up and accepting our key (if we are using ssh), and (2) that the source directory is mounted (if it needs to be mounted) and readable. --- ccollect.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ccollect.sh b/ccollect.sh index e14dcfc..0444ff0 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -366,6 +366,8 @@ while [ "${i}" -lt "${no_sources}" ]; do _exit_err "Source ${c_source} is not readable. Skipping." fi fi + # Verify source is up and accepting connections before deleting any old backups + rsync "$source" >/dev/null || _exit_err "Source ${source} is not readable. Skipping." # # Destination is a path From 62e8190a941731a006cbe45673c6287fe400f41b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Jun 2009 09:50:05 +0200 Subject: [PATCH 02/13] Introduce consistent time sorting Based on patches by John Lawless . Skipped the sort changing part (from -tc to -t) c.patch: --- ccollect-0.7.1-b.sh 2009-05-24 21:32:00.000000000 -0700 +++ ccollect-0.7.1-c.sh 2009-05-24 21:39:43.000000000 -0700 @@ -40,10 +40,13 @@ VERSION=0.7.1 RELEASE="2009-02-02" HALF_VERSION="ccollect ${VERSION}" FULL_VERSION="ccollect ${VERSION} (${RELEASE})" +#TSORT="tc" ; NEWER="cnewer" +TSORT="t" ; NEWER="newer" + # # CDATE: how we use it for naming of the archives # DDATE: how the user should see it in our output (DISPLAY) # CDATE="date +%Y%m%d-%H%M" @@ -513,14 +516,14 @@ # # Check for backup directory to clone from: Always clone from the latest one! # - # Use ls -1c instead of -1t, because last modification maybe the same on all - # and metadate update (-c) is updated by rsync locally. - # - last_dir="$(pcmd ls -tcp1 "${ddir}" | grep '/$' | head -n 1)" || \ + # Depending on your file system, you may want to sort on: + # 1. mtime (modification time) with TSORT=t, or + # 2. ctime (last change time, usually) with TSORT=tc + last_dir="$(pcmd ls -${TSORT}p1 "${ddir}" | grep '/$' | head -n 1)" || \ _exit_err "Failed to list contents of ${ddir}." # # clone from old backup, if existing # d.patch: --- ccollect-0.7.1-c.sh 2009-05-24 21:39:43.000000000 -0700 +++ ccollect-0.7.1-d.sh 2009-05-24 21:47:09.000000000 -0700 @@ -492,12 +492,12 @@ if [ "${count}" -ge "${c_interval}" ]; then substract=$((${c_interval} - 1)) remove=$((${count} - ${substract})) _techo "Removing ${remove} backup(s)..." - pcmd ls -p1 "$ddir" | grep "^${INTERVAL}\..*/\$" | \ - sort -n | head -n "${remove}" > "${TMP}" || \ + pcmd ls -${TSORT}p1r "$ddir" | grep "^${INTERVAL}\..*/\$" | \ + head -n "${remove}" > "${TMP}" || \ _exit_err "Listing old backups failed" i=0 while read to_remove; do eval remove_$i=\"${to_remove}\" Signed-off-by: Nico Schottelius --- ccollect.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ccollect.sh b/ccollect.sh index 0444ff0..e1555ea 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -45,9 +45,11 @@ FULL_VERSION="ccollect ${VERSION} (${RELEASE})" # # CDATE: how we use it for naming of the archives # DDATE: how the user should see it in our output (DISPLAY) +# TSORT: how to sort: tc = ctime, t = mtime # CDATE="date +%Y%m%d-%H%M" DDATE="date +%Y-%m-%d-%H:%M:%S" +TSORT="tc" # # unset parallel execution @@ -491,8 +493,8 @@ while [ "${i}" -lt "${no_sources}" ]; do remove=$((${count} - ${substract})) _techo "Removing ${remove} backup(s)..." - pcmd ls -p1 "$ddir" | grep "^${INTERVAL}\..*/\$" | \ - sort -n | head -n "${remove}" > "${TMP}" || \ + pcmd ls -${TSORT}p1r "$ddir" | grep "^${INTERVAL}\..*/\$" | \ + head -n "${remove}" > "${TMP}" || \ _exit_err "Listing old backups failed" i=0 @@ -518,7 +520,7 @@ while [ "${i}" -lt "${no_sources}" ]; do # Use ls -1c instead of -1t, because last modification maybe the same on all # and metadate update (-c) is updated by rsync locally. # - last_dir="$(pcmd ls -tcp1 "${ddir}" | grep '/$' | head -n 1)" || \ + last_dir="$(pcmd ls -${TSORT}p1 "${ddir}" | grep '/$' | head -n 1)" || \ _exit_err "Failed to list contents of ${ddir}." # From 382c159b413ce00a05d49f881e509a5234bdd259 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Jun 2009 09:55:38 +0200 Subject: [PATCH 03/13] Beautify a comment Signed-off-by: Nico Schottelius --- ccollect.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ccollect.sh b/ccollect.sh index e1555ea..cd13ac8 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -368,8 +368,11 @@ while [ "${i}" -lt "${no_sources}" ]; do _exit_err "Source ${c_source} is not readable. Skipping." fi fi + + # # Verify source is up and accepting connections before deleting any old backups - rsync "$source" >/dev/null || _exit_err "Source ${source} is not readable. Skipping." + # + rsync "${source}" >/dev/null || _exit_err "Source ${source} is not readable. Skipping." # # Destination is a path From 2b31f8f229ffd02d53fa82f4fc9e8adc1de275ed Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Jun 2009 09:56:13 +0200 Subject: [PATCH 04/13] add changes for the next release Signed-off-by: Nico Schottelius --- doc/changes/next | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 doc/changes/next diff --git a/doc/changes/next b/doc/changes/next new file mode 100644 index 0000000..0d7bd1f --- /dev/null +++ b/doc/changes/next @@ -0,0 +1,2 @@ +* Introduce consistenst time sorting (John Lawless) +* Check for source connectivity before trying backup (John Lawless) From 142fd24fc8f5efdcd2afe644a898731e0da7e839 Mon Sep 17 00:00:00 2001 From: jll2 Date: Mon, 22 Jun 2009 12:54:06 -0700 Subject: [PATCH 05/13] Add ARM to GNU/Linux architecture list I run ccollect nightly on a Thecus N2100 running Debian-ARM. The Linksys NSLU2 also runs an ARM processor and I have lightly tested ccollect on that under SlugOS. --- doc/ccollect.text | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ccollect.text b/doc/ccollect.text index 124f060..f1451f8 100644 --- a/doc/ccollect.text +++ b/doc/ccollect.text @@ -21,7 +21,7 @@ Supported and tested operating systems and architectures ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `ccollect` was successfully tested on the following platforms: -- GNU/Linux on amd64/hppa/i386/ppc +- GNU/Linux on amd64/hppa/i386/ppc/ARM - FreeBSD on amd64/i386 - Mac OS X 10.5 - NetBSD on alpha/amd64/i386/sparc/sparc64 From 544a7d269ec9d4546b03879b18bab7180636a3e8 Mon Sep 17 00:00:00 2001 From: jll2 Date: Wed, 24 Jun 2009 17:01:14 -0700 Subject: [PATCH 06/13] Create rsync_failure_codes option. User may optionally create a file rsync_failure_codes with a newline-separated list of rsync return codes that are to be regarded as complete failure. If rsync exits with such a code, then the backup will be marked for deletion during the next ccollect run (if delete_incomplete). I added documentation for this feature in doc/ccollect.text In my experience (yours may differ), two rsync exit codes that belong in this file are 12 and 255. I have seen 12 result from ssh errors and 255 result from a kernel module conflict. In both cases, the resulting backups were empty. Without the rsync_failure_codes option, such errors cause good backups to be deleted, as per c_interval, leaving behind the new empty backups. In the long run, we may want a different and more comprehensive method for analyzing rsync errors. In the short run, I find this option necessary. --- ccollect.sh | 36 ++++++++++++++++++++++++++---------- doc/ccollect.text | 10 ++++++++++ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/ccollect.sh b/ccollect.sh index d6831bc..2b67ba7 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -281,7 +281,8 @@ while [ "${i}" -lt "${no_sources}" ]; do c_dest="${backup}/destination" c_pre_exec="${backup}/pre_exec" c_post_exec="${backup}/post_exec" - for opt in exclude verbose very_verbose rsync_options summary delete_incomplete remote_host ; do + for opt in exclude verbose very_verbose rsync_options summary delete_incomplete \ + remote_host rsync_failure_codes ; do if [ -f "${backup}/$opt" -o -f "${backup}/no_$opt" ]; then eval c_$opt=\"${backup}/$opt\" else @@ -530,16 +531,31 @@ while [ "${i}" -lt "${no_sources}" ]; do _techo "Transferring files..." rsync "$@" "${source}" "${destination_full}"; ret=$? - - # - # remove marking here - # - pcmd rm "${destination_dir}.${c_marker}" || \ - _exit_err "Removing ${destination_dir}/${c_marker} failed." - _techo "Finished backup (rsync return code: $ret)." - if [ "${ret}" -ne 0 ]; then - _techo "Warning: rsync exited non-zero, the backup may be broken (see rsync errors)." + + # + # Check if rsync exit code indicates failure. + # + fail="" + if [ -f "$c_rsync_failure_codes" ]; then + while read code ; do + if [ "$ret" = "$code" ]; then + fail=1 + fi + done <"$c_rsync_failure_codes" + fi + + # + # Remove marking here unless rsync failed. + # + if [ -z "$fail" ]; then + pcmd rm "${destination_dir}.${c_marker}" || \ + _exit_err "Removing ${destination_dir}/${c_marker} failed." + if [ "${ret}" -ne 0 ]; then + _techo "Warning: rsync exited non-zero, the backup may be broken (see rsync errors)." + fi + else + _techo "Warning: rsync failed with return code $ret." fi # diff --git a/doc/ccollect.text b/doc/ccollect.text index f1451f8..3d9c480 100644 --- a/doc/ccollect.text +++ b/doc/ccollect.text @@ -359,6 +359,7 @@ Additionally a source may have the following files: - `delete_incomplete` delete incomplete backups - `remote_host` host to backup to + - `rsync_failure_codes` list of rsync exit codes that indicate complete failure Example: @@ -574,6 +575,15 @@ If you create the file `delete_incomplete` in a source specification directory, was interrupted) and remove them. Without this file `ccollect` will only warn the user. +Detailed description of "rsync_failure_codes" +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +If you have the file `rsync_failure_codes` in your source configuration +directory, it should contain a newline-separated list of numbers representing +rsync exit codes. If rsync exits with any code in this list, a marker will +be left in the destination directory indicating failure of this backup. If +you have enabled delete_incomplete, then this backup will be deleted during +the next ccollect run on the same interval. + Hints ----- From 97df2c14dec483d54e21cf77e8aadc9a7d9b6e87 Mon Sep 17 00:00:00 2001 From: jll2 Date: Thu, 25 Jun 2009 16:20:00 -0700 Subject: [PATCH 07/13] Update the destination directory's mtime with each backup. After rsync, the destination directory's mtime reflects the modification time of its immediate contents. This patch overrides that and sets the mtime to the time that the backup finished. With this patch, the age of a backup can be assessed by looking at its mtime. The advantages of this are (1) that mtime can be preserved, via cp -a or rsync -a, when copying a backup repository to a new hard disk or a new machine and (2) that incorrect mtimes, such as might happen after a user meddles with his backup repository, can be, via touch, corrected. The disadvantage is that mtime for the immediate contents of the destination directory is lost. --- ccollect.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ccollect.sh b/ccollect.sh index bb8549b..7f5ae67 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -536,6 +536,11 @@ while [ "${i}" -lt "${no_sources}" ]; do rsync "$@" "${source}" "${destination_full}"; ret=$? _techo "Finished backup (rsync return code: $ret)." + # + # Set modification time (mtime) to current time + # + pcmd touch "${destination_dir}" + # # Check if rsync exit code indicates failure. # From 010449bafad648f1df3d36481f891bc00c31640c Mon Sep 17 00:00:00 2001 From: jll2 Date: Thu, 25 Jun 2009 20:35:13 -0700 Subject: [PATCH 08/13] Add option to sort backup directories based on modification time. By default, ccollect.sh sorts backup directories based on last change time (ctime). This adds the option to sort based on modification time (mtime). I have updated doc/ccollect.text but it needs some work to simplify and explain the issue. --- ccollect.sh | 12 ++++++++---- doc/ccollect.text | 13 +++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ccollect.sh b/ccollect.sh index 7f5ae67..7c41352 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -285,7 +285,7 @@ while [ "${i}" -lt "${no_sources}" ]; do c_pre_exec="${backup}/pre_exec" c_post_exec="${backup}/post_exec" for opt in exclude verbose very_verbose rsync_options summary delete_incomplete \ - remote_host rsync_failure_codes ; do + remote_host rsync_failure_codes mtime ; do if [ -f "${backup}/$opt" -o -f "${backup}/no_$opt" ]; then eval c_$opt=\"${backup}/$opt\" else @@ -293,6 +293,13 @@ while [ "${i}" -lt "${no_sources}" ]; do fi done + # + # With mtime option, sort backup directories with mtime (default is ctime) + # + if [ -f "$c_mtime" ] ; then + TSORT="t" + fi + # # Marking backups: If we abort it's not removed => Backup is broken # @@ -496,9 +503,6 @@ while [ "${i}" -lt "${no_sources}" ]; do # # Check for backup directory to clone from: Always clone from the latest one! # - # Use ls -1c instead of -1t, because last modification maybe the same on all - # and metadate update (-c) is updated by rsync locally. - # last_dir="$(pcmd ls -${TSORT}p1 "${ddir}" | grep '/$' | head -n 1)" || \ _exit_err "Failed to list contents of ${ddir}." diff --git a/doc/ccollect.text b/doc/ccollect.text index 3d9c480..9781387 100644 --- a/doc/ccollect.text +++ b/doc/ccollect.text @@ -360,6 +360,7 @@ Additionally a source may have the following files: - `delete_incomplete` delete incomplete backups - `remote_host` host to backup to - `rsync_failure_codes` list of rsync exit codes that indicate complete failure + - `mtime` Sort backup directories based on their modification time Example: @@ -584,6 +585,18 @@ be left in the destination directory indicating failure of this backup. If you have enabled delete_incomplete, then this backup will be deleted during the next ccollect run on the same interval. +mtime +^^^^^ +By default, ccollect.sh chooses the most recent backup directory for cloning or +the oldest for deletion based on the directory's last change time (ctime). +With this option, the sorting is done based on modification time (mtime). With +this version of ccollect.sh, the ctime and mtime of your backups will normally +be the same and this option has no effect. However, if you, for example, move +your backups to another hard disk using cp -a or rsync -a, you should use this +option because the ctimes are not preserved during such operations. + +If you have any backups in your repository made with ccollect version 0.7.1 or +earlier, do not use this option and do not move your repository. Hints ----- From dd7a0474088402f92a9de89f375718d4886f6245 Mon Sep 17 00:00:00 2001 From: jll2 Date: Thu, 25 Jun 2009 21:34:42 -0700 Subject: [PATCH 09/13] Add option quiet_if_down. If a source is not connectable, ccollect.sh issues a series of error messages such as: $ ccollect.sh "int 1" dummy 2009-06-25-21:04:14: ccollect 0.7.1: Beginning backup using interval int 1 [dummy] 2009-06-25-21:04:14: Beginning to backup [dummy] ssh: connect to host Ha port 20: No route to host [dummy] rsync: connection unexpectedly closed (0 bytes received so far) [receiver] [dummy] rsync error: unexplained error (code 255) at io.c(600) [receiver=3.0.5] [dummy] 2009-06-25-21:04:17: Error: source Ha:/tmp is not readable. Skipping. 2009-06-25-21:04:17: Finished If you expect the source to be up, you want to see these messages. However, for a notebook computer or other portable machine, it may be normal for it to be disconnected. If quiet_if_down is specified for that source, then the ssh and rsync errors are suppressed and the "Error:" prefix is removed from the "skipping" message: $ ccollect.sh "int 1" dummy 2009-06-25-21:03:33: ccollect 0.7.1: Beginning backup using interval int 1 [dummy] 2009-06-25-21:03:34: Beginning to backup [dummy] 2009-06-25-21:03:37: Source Ha:/tmp is not readable. Skipping. 2009-06-25-21:03:37: Finished I considered the alternative implementation of adding the logic to ccollect_analyse_logs.sh to enable it to separate rsync messages generated the initial connection test from messages generated by rsync used for an actual backup data transfer. Adding this approach to ccollect.sh appeared much simpler. --- ccollect.sh | 11 +++++++++-- doc/ccollect.text | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ccollect.sh b/ccollect.sh index 7c41352..59a0b02 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -285,7 +285,7 @@ while [ "${i}" -lt "${no_sources}" ]; do c_pre_exec="${backup}/pre_exec" c_post_exec="${backup}/post_exec" for opt in exclude verbose very_verbose rsync_options summary delete_incomplete \ - remote_host rsync_failure_codes mtime ; do + remote_host rsync_failure_codes mtime quiet_if_down ; do if [ -f "${backup}/$opt" -o -f "${backup}/no_$opt" ]; then eval c_$opt=\"${backup}/$opt\" else @@ -368,7 +368,14 @@ while [ "${i}" -lt "${no_sources}" ]; do # # Verify source is up and accepting connections before deleting any old backups # - rsync "${source}" >/dev/null || _exit_err "Source ${source} is not readable. Skipping." + if ! rsync "${source}" >/dev/null 2>"${TMP}" ; then + if [ -f "${c_quiet_if_down}" ]; then + _exit_err "Source ${source} is not readable. Skipping." + else + cat "${TMP}" + _exit_err "Error: source ${source} is not readable. Skipping." + fi + fi # # Destination is a path diff --git a/doc/ccollect.text b/doc/ccollect.text index 9781387..9a76837 100644 --- a/doc/ccollect.text +++ b/doc/ccollect.text @@ -361,6 +361,7 @@ Additionally a source may have the following files: - `remote_host` host to backup to - `rsync_failure_codes` list of rsync exit codes that indicate complete failure - `mtime` Sort backup directories based on their modification time + - `quiet_if_down` Suppress error messages if source is not connectable Example: @@ -585,8 +586,8 @@ be left in the destination directory indicating failure of this backup. If you have enabled delete_incomplete, then this backup will be deleted during the next ccollect run on the same interval. -mtime -^^^^^ +Detailed description of "mtime" +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ By default, ccollect.sh chooses the most recent backup directory for cloning or the oldest for deletion based on the directory's last change time (ctime). With this option, the sorting is done based on modification time (mtime). With @@ -596,7 +597,15 @@ your backups to another hard disk using cp -a or rsync -a, you should use this option because the ctimes are not preserved during such operations. If you have any backups in your repository made with ccollect version 0.7.1 or -earlier, do not use this option and do not move your repository. +earlier, do not use this option. + +Detailed description of "quiet_if_down" +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +By default, ccollect.sh emits a series of error messages if a source is not +connectable. With this option enabled, ccollect.sh still reports that the +source is not connectable but the associated error messages generated by +rsync or ssh are suppressed. You may want to use this option for sources, +like notebook PCs, that are often disconnected. Hints ----- From 0b064e0565191015249dbd5a5f3a2cd057ecdeae Mon Sep 17 00:00:00 2001 From: jll2 Date: Fri, 26 Jun 2009 14:09:21 -0700 Subject: [PATCH 10/13] Beautify: remove trailing white space. If your editor does not highlight trailing white space, you won't see a difference. --- ccollect.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ccollect.sh b/ccollect.sh index 59a0b02..e842053 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -1,19 +1,19 @@ #!/bin/sh -# +# # 2005-2009 Nico Schottelius (nico-ccollect at schottelius.org) -# +# # This file is part of ccollect. # # ccollect is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # ccollect is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with ccollect. If not, see . # @@ -163,7 +163,7 @@ while [ "$#" -ge 1 ]; do if [ "${NO_MORE_ARGS}" = 1 ]; then eval source_${no_sources}=\"${arg}\" no_sources=$((${no_sources}+1)) - + # make variable available for subscripts eval export source_${no_sources} else @@ -415,13 +415,13 @@ while [ "${i}" -lt "${no_sources}" ]; do # - insert ccollect default parameters # - insert options # - insert user options - + # # rsync standard options # set -- "$@" "--archive" "--delete" "--numeric-ids" "--relative" \ - "--delete-excluded" "--sparse" + "--delete-excluded" "--sparse" # # exclude list @@ -480,7 +480,7 @@ while [ "${i}" -lt "${no_sources}" ]; do | sed 's/^ *//g')" || _exit_err "Counting backups failed" _techo "Existing backups: ${count} Total keeping backups: ${c_interval}" - + if [ "${count}" -ge "${c_interval}" ]; then substract=$((${c_interval} - 1)) remove=$((${count} - ${substract})) @@ -512,7 +512,7 @@ while [ "${i}" -lt "${no_sources}" ]; do # last_dir="$(pcmd ls -${TSORT}p1 "${ddir}" | grep '/$' | head -n 1)" || \ _exit_err "Failed to list contents of ${ddir}." - + # # clone from old backup, if existing # @@ -520,7 +520,7 @@ while [ "${i}" -lt "${no_sources}" ]; do set -- "$@" "--link-dest=${ddir}/${last_dir}" _techo "Hard linking from ${last_dir}" fi - + # set time when we really begin to backup, not when we began to remove above destination_date=$(${CDATE}) From 76e6094247ee4ca08111f631c000a03cb2d993e5 Mon Sep 17 00:00:00 2001 From: jll2 Date: Fri, 26 Jun 2009 14:42:45 -0700 Subject: [PATCH 11/13] Simplify interval code. Eight lines and two variables are removed which makes the code, I think, easier to read. The main motivation for this change, however, is that it makes ccollect.sh more friendly to (future) auto interval selection. The removed lines and variables assumed that the interval was known prior to the start of the source loop. With auto interval selection, the selected interval can be different for each source. --- ccollect.sh | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/ccollect.sh b/ccollect.sh index e842053..65e10d9 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -237,14 +237,6 @@ if [ -x "${CPREEXEC}" ]; then [ "${ret}" -eq 0 ] || _exit_err "${CPREEXEC} failed. Aborting" fi -# -# check default configuration -# - -D_FILE_INTERVAL="${CDEFAULTS}/intervals/${INTERVAL}" -D_INTERVAL=$(cat "${D_FILE_INTERVAL}" 2>/dev/null) - - # # Let's do the backup # @@ -346,7 +338,7 @@ while [ "${i}" -lt "${no_sources}" ]; do c_interval="$(cat "${backup}/intervals/${INTERVAL}" 2>/dev/null)" if [ -z "${c_interval}" ]; then - c_interval="${D_INTERVAL}" + c_interval="$(cat "${CDEFAULTS}/intervals/${INTERVAL}" 2>/dev/null)" if [ -z "${c_interval}" ]; then _exit_err "No definition for interval \"${INTERVAL}\" found. Skipping." From 72830a4647188d34da7656ea2d166347c57333e2 Mon Sep 17 00:00:00 2001 From: jll2 Date: Fri, 26 Jun 2009 14:54:28 -0700 Subject: [PATCH 12/13] If the user specifies "delete_incomplete", this patch makes it so all incomplete backups are deleted, not just the ones with the particular interval that the user specified. The advantage of this is that those to-be-deleted incomplete backups will not interfere with calculations required for automatic interval selection. --- ccollect.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ccollect.sh b/ccollect.sh index 65e10d9..71c032b 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -452,7 +452,7 @@ while [ "${i}" -lt "${no_sources}" ]; do # # Check for incomplete backups # - pcmd ls -1 "$ddir/${INTERVAL}"*".${c_marker}" 2>/dev/null | while read marker; do + pcmd ls -1 "${ddir}/"*".${c_marker}" 2>/dev/null | while read marker; do incomplete="$(echo ${marker} | sed "s/\\.${c_marker}\$//")" _techo "Incomplete backup: ${incomplete}" if [ -f "${c_delete_incomplete}" ]; then From 6fd22b641697ecbbb0bbfc1eab1301836f44c191 Mon Sep 17 00:00:00 2001 From: jll2 Date: Fri, 26 Jun 2009 15:22:09 -0700 Subject: [PATCH 13/13] Move "interval definition section". The interval definition section was down to just before the maximum backup check. This makes the code more friendly to automatic interval selection. Auto interval selection needs to have ddir defined first and it is best if it is done after delete_incomplete. This change accomplishes that while still placing it before the maximum backup check which needs to know the interval. --- ccollect.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ccollect.sh b/ccollect.sh index 71c032b..a61af21 100755 --- a/ccollect.sh +++ b/ccollect.sh @@ -332,19 +332,6 @@ while [ "${i}" -lt "${no_sources}" ]; do fi fi - # - # interval definition: First try source specific, fallback to default - # - c_interval="$(cat "${backup}/intervals/${INTERVAL}" 2>/dev/null)" - - if [ -z "${c_interval}" ]; then - c_interval="$(cat "${CDEFAULTS}/intervals/${INTERVAL}" 2>/dev/null)" - - if [ -z "${c_interval}" ]; then - _exit_err "No definition for interval \"${INTERVAL}\" found. Skipping." - fi - fi - # # Source checks # @@ -464,6 +451,19 @@ while [ "${i}" -lt "${no_sources}" ]; do fi done + # + # interval definition: First try source specific, fallback to default + # + c_interval="$(cat "${backup}/intervals/${INTERVAL}" 2>/dev/null)" + + if [ -z "${c_interval}" ]; then + c_interval="$(cat "${CDEFAULTS}/intervals/${INTERVAL}" 2>/dev/null)" + + if [ -z "${c_interval}" ]; then + _exit_err "No definition for interval \"${INTERVAL}\" found. Skipping." + fi + fi + # # check if maximum number of backups is reached, if so remove # use grep and ls -p so we only look at directories