Commit graph

219 commits

Author SHA1 Message Date
Nico Schottelius
23b2fcee08 move -* check at the right location
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-10-25 15:26:17 +01:00
Nico Schottelius
25d8a2e2fb remove double --help section
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-10-25 15:24:18 +01:00
Nico Schottelius
f549334226 Add rsync arguments for source checking
Fix proposed by Nikita Koshikov:

--------------------------------------------------------------------------------
[...]

[guard] + set -- --archive --delete --numeric-ids --relative --delete-excluded --sparse --stats -v
[guard] + '[' -f /etc/ccollect/sources/guard/rsync_options ']'
[guard] + read line
[guard] + set -- --archive --delete --numeric-ids --relative --delete-excluded --sparse --stats -v
--password-file=/etc/ccollect/passwd
[guard] + read line
[guard] + rsync backup@192.168.1.8::etc
Password:

In this place it's sit and waiting for password. If I comment out related ccollect code section everything
start working as expected. I had to modify this part to be look like:

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

Then checking host activity is passed and backup process running successful.

--------------------------------------------------------------------------------

Changed it to "$@" "$source" instead, to be consistent and use options
before source.

Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-08-21 13:03:38 +02:00
Nico Schottelius
26f4ae777b prepare release 0.8
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-08-20 17:36:09 +02:00
Nico Schottelius
8cc833a7b1 only change mtime of main dir, if sorting by mtime is selected
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-08-20 16:25:25 +02:00
Nico Schottelius
02670a813c synchronise order of options in ccollect with documentation
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-29 09:10:30 +02:00
Nico Schottelius
4696590a73 Create SDATE, similar to DDATE and CDATE
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-28 17:16:13 +02:00
Nico Schottelius
4ba0dab260 Create function 'delete_from_file()'
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-28 12:43:23 +02:00
Nico Schottelius
e6a0300b9b Simplify removal code
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-28 07:47:48 +02:00
Nico Schottelius
9aa111d21b export TMP to subscripts
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-28 07:46:43 +02:00
Nico Schottelius
428670b4e7 comment cleanups
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-27 09:52:18 +02:00
Nico Schottelius
c2bc225dc0 SORT: make it more explicit, which sorting options are used
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-27 09:39:33 +02:00
Nico Schottelius
483cfee90c Reorder: All checks being done in the same place
All configurations are checked in the same place

Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-27 09:37:50 +02:00
Nico Schottelius
cbf1b7cf0e Simplify error printing, if quiet_if_down is set
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-27 09:17:06 +02:00
Nico Schottelius
b014c00d24 Remove double code imported with merge
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-27 09:16:35 +02:00
Nico Schottelius
d61c9625f4 Only check configuration options, if the base is exitsing
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-27 09:06:01 +02:00
Nico Schottelius
65c34deb43 remove unecessary whitespace in line 204 :-)
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-27 09:01:13 +02:00
Nico Schottelius
2b890b0316 Merge commit 'john/updates'
Fixed alot of conflicts due to parallel work, but it looks very good now!

Conflicts:
	ccollect.sh
2009-07-24 09:09:16 +02:00
Nico Schottelius
b44fdb6107 some cleanups
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-24 08:58:48 +02:00
Nico Schottelius
ed30a4d25b Remove check for directories with -a
Type of source is checked later anyway and using
ls -p1 results in "dir/", which we should cleanup
with "sed 's;/$;;' again, which is ugly.

Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-23 17:56:41 +02:00
Nico Schottelius
8a87e7effa Move option check below the check for existence of source
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-23 17:53:35 +02:00
Nico Schottelius
f5e1920a15 join source handling for --all and normal
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-23 17:47:54 +02:00
Nico Schottelius
8491a54b0d extract the interval handling from parsing
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-23 17:46:04 +02:00
Nico Schottelius
debdd9d004 BUGFIX: Fix --all handling
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-23 17:39:42 +02:00
Nico Schottelius
37dcda8e3b BUGFIX: ignore -- as parameter
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-23 17:37:55 +02:00
Nico Schottelius
5da5506c65 add quotes to every possible problematic variable, add braces
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-01 22:39:42 +02:00
Nico Schottelius
09ed55a17e only consider directories as sources
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-01 17:09:30 +02:00
Nico Schottelius
a9aad1ed8f correct indent
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-01 17:08:59 +02:00
Nico Schottelius
bd1e365ca0 replace multiple echos with one cat
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-01 12:42:32 +02:00
Nico Schottelius
ca1231a576 begin to implement new style option parsing
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-01 12:03:40 +02:00
Nico Schottelius
194148b5b3 update url of homepage
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-07-01 10:00:18 +02:00
jll2
6fd22b6416 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.
2009-06-26 15:22:09 -07:00
jll2
72830a4647 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.
2009-06-26 14:54:28 -07:00
jll2
76e6094247 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.
2009-06-26 14:42:45 -07:00
jll2
0b064e0565 Beautify: remove trailing white space.
If your editor does not highlight trailing white space,
you won't see a difference.
2009-06-26 14:09:21 -07:00
jll2
dd7a047408 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.
2009-06-25 21:34:42 -07:00
jll2
010449bafa 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.
2009-06-25 20:35:13 -07:00
jll2
97df2c14de 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.
2009-06-25 16:20:00 -07:00
jll2
923350907d Merge branch 'master' of git@github.com:jll2/ccollect into updates 2009-06-24 19:58:20 -07:00
jll2
544a7d269e 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.
2009-06-24 17:01:14 -07:00
jll2
64b5ae8b03 Defensive programming patch:
"set -u" was added to make sure that there will never be misspelled or
uninitialized variables in ccollect.sh.
2009-06-24 18:42:39 +02:00
jll2
d6ea94c6dc Fix delete_incomplete bugs:
1).  On systems I tried, delete_incomplete failed because the line:

< pcmd rm $VVERBOSE -rf "${ddir}/${realincomplete}" || \

should read:

> pcmd rm $VVERBOSE -rf "${realincomplete}" || \

(Is this true of all systems?)

2).  The marker file was not deleted.  Code was added to delete it.

3).  The delete_incomplete code was simplified.
2009-06-20 21:06:10 +02:00
jll2
ea16af51b2 Simplify handling of command-line verbose option:
Previously, there was a $VERBOSE script variable that was set according to
the "-v" command line option and then reset to null within each source
sub-shell.  With no loss of functionality, this patch removes all references
to that variable.

This makes the script 13 lines shorter.
2009-06-20 11:42:49 +02:00
jll2
a4c61e7b68 Bug fix for very_verbose:
According to the documentation, "if [the very_verbose] file exists in the
source specification -v will be passed to rsync, rm and mkdir."  Previously,
the -v option was passed only to rsync.  This patch passes it to rm and mkdir
as well.

Actually, as per the behavior of the previous version, it is verbose that
sends the -v option to rsync while very_verbose sends it the -vv option.  I
left it this way because this behavior seems reasonable.  Maybe the
documentation should be corrected on this point.
2009-06-20 11:40:01 +02:00
jll2
192b55b98d Initialize four variables to prevent unwanted interaction with user's environment. 2009-06-20 11:37:14 +02:00
jll2
122982b0b9 Modifies ccollect.sh's interpretation of options:
1).  If an option doesn't exist in a source directory, check the defaults directory.
2).  For every option, create a corresponding "no_" option so that a source directory
     can override an option set in defaults.
(i.patch)
2009-06-20 11:36:37 +02:00
Nico Schottelius
ba538ea623 Beautify a comment
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-06-10 09:55:38 +02:00
Nico Schottelius
bce57a1ac1 Introduce consistent time sorting
Based on patches by John Lawless <jll2_8854b@redwoodscientific.com>.
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 <nico@ikn.schottelius.org>
2009-06-10 09:50:05 +02:00
John Lawless
ae23a04925 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.
2009-05-25 08:39:28 +02:00
Nico Schottelius
38ca0a1546 Revert "Keep a symlink to the current backup around. This allows us to"
This patch is broken for non local destinations.

This reverts commit 6de3c9877c.
2009-02-04 15:12:27 +01:00