From dd7a0474088402f92a9de89f375718d4886f6245 Mon Sep 17 00:00:00 2001 From: jll2 Date: Thu, 25 Jun 2009 21:34:42 -0700 Subject: [PATCH] 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 -----