From: Andre Noll Date: Mon, 7 Feb 2011 16:56:36 +0000 (+0100) Subject: Merge branch 't/logfile_only_for_daemon' X-Git-Tag: v0.1.5~20 X-Git-Url: http://git.tuebingen.mpg.de/?p=dss.git;a=commitdiff_plain;h=69add8d2b5d6c8f402e9f94d47df732479535f2d;hp=c279f1a5bd474f002f8486aafbfd0b7f0d4e15c3 Merge branch 't/logfile_only_for_daemon' --- diff --git a/INSTALL b/INSTALL index 1043ec5..ff4274b 100644 --- a/INSTALL +++ b/INSTALL @@ -51,7 +51,7 @@ Then execute the commands In order to print the list of all snapshots created so far, use - dss --list + dss --ls Yes, it's really that easy. Of course, dss supports many more features and config options such as taking snapshots from remote diff --git a/Makefile b/Makefile index f59e315..99b8286 100644 --- a/Makefile +++ b/Makefile @@ -45,10 +45,12 @@ dss.1: dss dss.1.inc clean: rm -f *.o dss dss.1 dss.1.html Makefile.deps *.ppm *.png *~ cmdline.c cmdline.h index.html -index.html: dss.1.html index.html.in INSTALL README +index.html: dss.1.html index.html.in INSTALL README NEWS sed -e '/@README@/,$$d' index.html.in > $@ grutatxt -nb < README >> $@ - sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' index.html.in >> $@ + sed -e '1,/@README@/d' -e '/@NEWS@/,$$d' index.html.in >> $@ + grutatxt -nb < NEWS >> $@ + sed -e '1,/@NEWS@/d' -e '/@INSTALL@/,$$d' index.html.in >> $@ grutatxt -nb < INSTALL >> $@ sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' index.html.in >> $@ sed -e '1,/Return to Main Contents/d' -e '/Index/,$$d' dss.1.html >> $@ diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..6b9deec --- /dev/null +++ b/NEWS @@ -0,0 +1,36 @@ +0.1.4 (2010-11-08) +~~~~~~~~~~~~~~~~~~ +This version of dss contains some new features, many improvements of +existing features and several bug fixes. + +Support for resuming snapshot creation after restart has been added +and snapshot removal is deferred until at least one current snapshot +exists. The internal handling of the various hooks has been simplified +and many error messages have been clarified. On SIGHUP, dss now writes +its configuration and internal state to the log file. + +0.1.3 (2009-06-06) +~~~~~~~~~~~~~~~~~~ +You can now specify pre-rm/post-rm-hooks that are executed whenever +a snapshot is deleted. This release adds better compatibility with +rsync 3.0, and avoids busy loops when automatically restarting the +rsync process. + +0.1.2 (2009-03-05) +~~~~~~~~~~~~~~~~~~ +This release includes the reason why a snapshot gets removed in the +log message. It will never remove the snapshot that is currently +being created. It will really pass the full path to the last complete +snapshot in the post_create_hook. + +0.1.1 (2008-11-13) +~~~~~~~~~~~~~~~~~~ +This release prevents busy loops on rsync exit code 13. It ignores +any snapshot directory with creation time > completion time. It +opens /dev/null for reading and writing when executing rsync. It shows +human readable snapshot creation duration when listing snapshots. It +restarts the rsync process if it returned with exit code 13. + +0.1.0 (2008-10-10) +~~~~~~~~~~~~~~~~~~ +Initial public release. diff --git a/daemon.c b/daemon.c index 17a171e..d48e30c 100644 --- a/daemon.c +++ b/daemon.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1997-2009 Andre Noll + * Copyright (C) 1997-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ diff --git a/df.c b/df.c index 37e2b43..513bd19 100644 --- a/df.c +++ b/df.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2009 Andre Noll + * Copyright (C) 2008-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ diff --git a/dss.c b/dss.c index e32e7e2..b4ad2d2 100644 --- a/dss.c +++ b/dss.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2009 Andre Noll + * Copyright (C) 2008-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -64,7 +64,106 @@ enum hook_status snapshot_removal_status; DEFINE_DSS_ERRLIST; +static const char const *hook_status_description[] = {HOOK_STATUS_ARRAY}; +/* may be called with ds == NULL. */ +static int disk_space_low(struct disk_space *ds) +{ + struct disk_space ds_struct; + + if (!ds) { + int ret = get_disk_space(".", &ds_struct); + if (ret < 0) + return ret; + ds = &ds_struct; + } + if (conf.min_free_mb_arg) + if (ds->free_mb < conf.min_free_mb_arg) + return 1; + if (conf.min_free_percent_arg) + if (ds->percent_free < conf.min_free_percent_arg) + return 1; + if (conf.min_free_percent_inodes_arg) + if (ds->percent_free_inodes < conf.min_free_percent_inodes_arg) + return 1; + return 0; +} + +static void dump_dss_config(const char *msg) +{ + const char dash[] = "-----------------------------"; + int ret; + FILE *log = logfile? logfile : stderr; + struct disk_space ds; + int64_t now = get_current_time(); + + if (conf.loglevel_arg > INFO) + return; + + fprintf(log, "%s <%s config> %s\n", dash, msg, dash); + fprintf(log, "\n*** disk space ***\n\n"); + ret = get_disk_space(".", &ds); + if (ret >= 0) { + DSS_INFO_LOG("disk space low: %s\n", disk_space_low(&ds)? + "yes" : "no"); + log_disk_space(&ds); + } else + DSS_ERROR_LOG("can not get free disk space: %s\n", + dss_strerror(-ret)); + + /* we continue on errors from get_disk_space */ + + fprintf(log, "\n*** command line and config file options ***\n\n"); + cmdline_parser_dump(log, &conf); + fprintf(log, "\n*** internal state ***\n\n"); + fprintf(log, + "pid: %d\n" + "logile: %s\n" + "snapshot_currently_being_removed: %s\n" + "path_to_last_complete_snapshot: %s\n" + "reference_snapshot: %s\n" + "snapshot_creation_status: %s\n" + "snapshot_removal_status: %s\n" + , + (int) getpid(), + logfile? conf.logfile_arg : "stderr", + snapshot_currently_being_removed? + snapshot_currently_being_removed->name : "(none)", + path_to_last_complete_snapshot? + path_to_last_complete_snapshot : "(none)", + name_of_reference_snapshot? + name_of_reference_snapshot : "(none)", + hook_status_description[snapshot_creation_status], + hook_status_description[snapshot_removal_status] + ); + if (create_pid != 0) + fprintf(log, + "create_pid: %" PRId32 "\n" + "create process is %sstopped\n" + , + create_pid, + create_process_stopped? "" : "not " + ); + if (remove_pid != 0) + fprintf(log, "remove_pid: %" PRId32 "\n", remove_pid); + if (next_snapshot_time != 0) + fprintf(log, "next snapshot due in %" PRId64 " seconds\n", + next_snapshot_time - now); + if (current_snapshot_creation_time != 0) + fprintf(log, "current_snapshot_creation_time: %" + PRId64 " (%" PRId64 " seconds ago)\n", + current_snapshot_creation_time, + now - current_snapshot_creation_time + ); + if (next_removal_check.tv_sec != 0) { + fprintf(log, "next removal check: %llu (%llu seconds ago)\n", + (long long unsigned)next_removal_check.tv_sec, + now - (long long unsigned)next_removal_check.tv_sec + ); + + } + fprintf(log, "%s %s\n", dash, msg, dash); +} /* a litte cpp magic helps to DRY */ #define COMMANDS \ @@ -127,25 +226,6 @@ static __printf_1_2 void dss_msg(const char* fmt,...) va_end(argp); } -static int disk_space_low(void) -{ - struct disk_space ds; - int ret = get_disk_space(".", &ds); - - if (ret < 0) - return ret; - if (conf.min_free_mb_arg) - if (ds.free_mb < conf.min_free_mb_arg) - return 1; - if (conf.min_free_percent_arg) - if (ds.percent_free < conf.min_free_percent_arg) - return 1; - if (conf.min_free_percent_inodes_arg) - if (ds.percent_free_inodes < conf.min_free_percent_inodes_arg) - return 1; - return 0; -} - static void dss_get_snapshot_list(struct snapshot_list *sl) { get_snapshot_list(sl, conf.unit_interval_arg, conf.num_intervals_arg); @@ -441,7 +521,7 @@ static int try_to_free_disk_space(void) const char *why; int low_disk_space; - ret = disk_space_low(); + ret = disk_space_low(NULL); if (ret < 0) return ret; low_disk_space = ret; @@ -903,24 +983,16 @@ static int change_to_dest_dir(void) return dss_chdir(conf.dest_dir_arg); } -static void dump_dss_config(const char *msg) -{ - if (conf.loglevel_arg > INFO) - return; - DSS_INFO_LOG("%s\n", msg); - cmdline_parser_dump(logfile? logfile : stderr, &conf); -} - static int handle_sighup(void) { int ret; DSS_NOTICE_LOG("SIGHUP, re-reading config\n"); - dump_dss_config("current config"); + dump_dss_config("old"); ret = parse_config_file(1); if (ret < 0) return ret; - dump_dss_config("new config"); + dump_dss_config("reloaded"); invalidate_next_snapshot_time(); return change_to_dest_dir(); } @@ -1354,10 +1426,10 @@ int main(int argc, char **argv) } if (conf.daemon_given) daemon_init(); - dump_dss_config("dss configuration"); ret = change_to_dest_dir(); if (ret < 0) goto out; + dump_dss_config("startup"); ret = setup_signal_handling(); if (ret < 0) goto out; diff --git a/dss.ggo b/dss.ggo index 8f1ec5c..1662e0d 100644 --- a/dss.ggo +++ b/dss.ggo @@ -1,9 +1,9 @@ -# Copyright (C) 2008-2009 Andre Noll +# Copyright (C) 2008-2010 Andre Noll # # Licensed under the GPL v2. For licencing details see COPYING. package "dss" -version "0.1.3" +version "0.1.4" purpose "the dyadic snapshot scheduler dss creates hardlink-based snapshots of a given directory on a remote @@ -269,7 +269,7 @@ option "pre-create-hook" r #~~~~~~~~~~~~~~~~~~~~~~~~~~ "Executed before snapshot creation" string typestr="command" -default = "/bin/true" +default = "true" optional details=" Execute this command before trying to create a new snapshot. @@ -288,7 +288,7 @@ option "post-create-hook" o #~~~~~~~~~~~~~~~~~~~~~~~~~~ "Executed after snapshot creation" string typestr="command" -default = "/bin/true" +default = "true" optional details=" Execute this after a snapshot has successfully been @@ -305,7 +305,7 @@ option "pre-remove-hook" - #~~~~~~~~~~~~~~~~~~~~~~~~~~ "Executed before snapshot removal" string typestr="command" -default = "/bin/true" +default = "true" optional details=" Execute this command before removing a snapshot. The full @@ -327,7 +327,7 @@ option "post-remove-hook" - #~~~~~~~~~~~~~~~~~~~~~~~~~~ "Executed after snapshot removal" string typestr="command" -default = "/bin/true" +default = "true" optional details=" Execute this after a snapshot has successfully been removed. As @@ -340,7 +340,7 @@ option "exit-hook" e #~~~~~~~~~~~~~~~~~~~ "Executed if run command exits" string typestr="command" -default = "/bin/true" +default = "true" optional details=" This hook is only used if the --run command was given which @@ -401,7 +401,8 @@ details=" Note that not every file system supports the concept of inodes. Moreover it is not possible to reliably detect whether this is the case. Therefore this feature is disabled by default. It's - safe to enable it for ext3 file systems on linux though. + safe to enable it for ext2/ext3/ext4 file systems on linux + though. A value of zero (the default) deactivates this check. " diff --git a/error.h b/error.h index b492c32..9e910e2 100644 --- a/error.h +++ b/error.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2009 Andre Noll + * Copyright (C) 2006-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ diff --git a/exec.c b/exec.c index a5d0cd0..2887cb2 100644 --- a/exec.c +++ b/exec.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2009 Andre Noll + * Copyright (C) 2003-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ diff --git a/fd.c b/fd.c index a0b897e..2b002c7 100644 --- a/fd.c +++ b/fd.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2009 Andre Noll + * Copyright (C) 2006-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ diff --git a/fd.h b/fd.h index 806f894..991afd4 100644 --- a/fd.h +++ b/fd.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2009 Andre Noll + * Copyright (C) 2006-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ diff --git a/index.html.in b/index.html.in index b42402f..d984844 100644 --- a/index.html.in +++ b/index.html.in @@ -23,6 +23,7 @@
[README] + [NEWS] [Download] [INSTALL] [License] @@ -41,6 +42,15 @@
+
+

+ NEWS +

+
+ + @NEWS@ + +

@@ -64,7 +74,7 @@ tarball - of the current tree. If you prefer to download the tarball of + of the current master branch. If you prefer to download the tarball of the latest release, select the corresponding snapshot link on the @@ -106,7 +116,7 @@

André Noll, maan@systemlinux.org -

Comments and bug reports are welcome Please provide +

Comments and bug reports are welcome. Please provide enough info such as the version of dss you are using and relevant parts of the logs. Including the string [dss] in the subject line is also a good idea. diff --git a/log.h b/log.h index 178c686..5d38c7b 100644 --- a/log.h +++ b/log.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1997-2009 Andre Noll + * Copyright (C) 1997-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ diff --git a/signal.c b/signal.c index d22cd59..3bbe87d 100644 --- a/signal.c +++ b/signal.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2009 Andre Noll + * Copyright (C) 2004-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ diff --git a/signal.h b/signal.h index a0e9899..0c5b3d8 100644 --- a/signal.h +++ b/signal.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2009 Andre Noll + * Copyright (C) 2007-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ diff --git a/snap.c b/snap.c index 1ff5fd7..41dc329 100644 --- a/snap.c +++ b/snap.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2009 Andre Noll + * Copyright (C) 2008-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ diff --git a/snap.h b/snap.h index 5c2f20b..b9659ae 100644 --- a/snap.h +++ b/snap.h @@ -1,26 +1,26 @@ /* - * Copyright (C) 2008-2009 Andre Noll + * Copyright (C) 2008-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ + /** The possible states for snapshot creation/removal. */ -enum hook_status { - /** We are ready to take the next snapshot. */ - HS_READY, - /** The pre-create/pre-remove hook has been started. */ - HS_PRE_RUNNING, - /** The pre-create/pre-remove hook exited successfully. */ - HS_PRE_SUCCESS, - /** The rsync/rm process is running. */ - HS_RUNNING, - /** The rsync/rm process exited successfully. */ - HS_SUCCESS, - /** The rsync/rm process needs to be restarted. */ - HS_NEEDS_RESTART, - /** The post-create/post-remove hook has been started. */ - HS_POST_RUNNING, -}; +#define HOOK_STATUS_ARRAY \ + HSA_ITEM(HS_READY, "ready for action"), \ + HSA_ITEM(HS_PRE_RUNNING, "pre-hook running"), \ + HSA_ITEM(HS_PRE_SUCCESS, "pre-hook completed successfully"), \ + HSA_ITEM(HS_RUNNING, "in progress"), \ + HSA_ITEM(HS_SUCCESS, "process terminated successfully"), \ + HSA_ITEM(HS_NEEDS_RESTART, "restart needed"), \ + HSA_ITEM(HS_POST_RUNNING, "post-hook running"), \ + + +#define HSA_ITEM(x, y) x +enum hook_status {HOOK_STATUS_ARRAY}; +#undef HSA_ITEM +#define HSA_ITEM(x, y) [x] = y + /** * The status of a snapshot. diff --git a/string.c b/string.c index 60c53d5..d370a81 100644 --- a/string.c +++ b/string.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2009 Andre Noll + * Copyright (C) 2004-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ diff --git a/time.c b/time.c index 0ad974b..3cc1ad6 100644 --- a/time.c +++ b/time.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2009 Andre Noll + * Copyright (C) 2005-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */