DEFINE_DSS_ERRLIST;
-/** Defines one dss command. */
-struct server_command {
- /** The name of the command. */
- const char *name;
- /** Pointer to the function that handles the command. */
- int (*handler)(int, char * const * const);
-};
/* a litte cpp magic helps to DRY */
-#define SERVER_COMMANDS \
- SERVER_COMMAND(ls) \
- SERVER_COMMAND(create) \
- SERVER_COMMAND(prune) \
- SERVER_COMMAND(daemon)
-#define SERVER_COMMAND(x) int com_ ##x(int, char * const * const);
-SERVER_COMMANDS
-#undef SERVER_COMMAND
-#define SERVER_COMMAND(x) {.name = #x, .handler = com_ ## x},
-static struct server_command command_list[] = {
- SERVER_COMMANDS
- {.name = NULL, .handler = NULL}
-};
-#undef SERVER_COMMAND
+#define COMMANDS \
+ COMMAND(ls) \
+ COMMAND(create) \
+ COMMAND(prune) \
+ COMMAND(run)
+#define COMMAND(x) int com_ ##x(int, char * const * const);
+COMMANDS
+#undef COMMAND
+#define COMMAND(x) if (conf.x ##_given) return com_ ##x(argc, argv);
+int call_command_handler(int argc, char * const * const argv)
+{
+ COMMANDS
+ return -E_INVALID_COMMAND;
+}
+#undef COMMAND
+#undef COMMANDS
/*
* complete, not being deleted: 1204565370-1204565371.Sun_Mar_02_2008_14_33-Sun_Mar_02_2008_14_43
return 1;
}
+int com_run(int argc, char * const * argv)
+{
+ return 42;
+}
+
int com_prune(int argc, char * const * argv)
{
int ret, dry_run = 0;
int main(int argc, char **argv)
{
- int i, ret;
+ int ret;
cmdline_parser(argc, argv, &conf); /* aborts on errors */
if (!conf.inputs_num) {
ret = dss_chdir(conf.dest_dir_arg);
if (ret < 0)
goto out;
- for (i = 0; command_list[i].name; i++) {
- if (strcmp(command_list[i].name, conf.inputs[0]))
- continue;
- ret = command_list[i].handler(conf.inputs_num, conf.inputs);
- goto out;
- }
- ret = -E_INVALID_COMMAND;
- make_err_msg("%s", conf.inputs[0]);
+ ret = call_command_handler(conf.inputs_num, conf.inputs);
out:
if (ret < 0)
log_err_msg(EMERG, -ret);
+#
+package "dss"
+version "0.0.1"
+purpose "the dyadic snapshot scheduler"
text "
dss snapshot aging is implemented in terms of intervals. There are
-package "dss"
-version "0.0.1"
-
option "config_file" c
#~~~~~~~~~~~~~~~~~~~~~
"(default='~/.dssrc')"
default="4"
optional
-option "logfile" L
+defgroup "command"
+groupdesc="
+ dss supports a couple of commands each of which corresponds to a different
+ command line option. Exactly one of these options must be given.
+"
+required
+
+groupoption "create" C
+#~~~~~~~~~~~~~~~~~~~~~
+"create a new snapshot"
+group="command"
+details="
+ Execute the rsync command to create a new snapshot.Mote that this
+ command does not care about free disk space.
+"
+groupoption "prune" P
+#~~~~~~~~~~~~~~~~~~~~
+"remove a redundant snapshot"
+group="command"
+details="
+ A snapshot is considered redundant if it ether belongs to
+ an interval greater than the maximum nuber of intervals,
+ or if it belongs to an interval that already contains more
+ than the desired number of snapshots.
+"
+
+groupoption "ls" L
+#~~~~~~~~~~~~~~~~~
+"print a list of all snapshots"
+group="command"
+details="
+ The list will contain all snapshots not matter of their state,
+ i.e. incomplete snapshots and snapshots being deleted will
+ also be listed.
+"
+
+groupoption "run" R
#~~~~~~~~~~~~~~~~~~
+"start creating and pruning snapshots"
+group="command"
+details="
+ This is the main mode of operation. Snapshots will be created
+ as needed and pruned automatically.
+"
+
+option "logfile" -
+#~~~~~~~~~~~~~~~~~
"logfile for the dss daemon process"
dss will start to remove snapshots (starting from the oldest
snapshot) until the free disk space exeecds this value.
"
-
-
-text "
-subcommands:
-
-ls:
-
- Print list of existing snapshots.
-
- Usage: ls
-
-free:
-
- Remove old snapshots in order to free space.
-
- Usage: free [size]
-
- Without size parameter, print the amount of free space on the file system
- in human-readable format.
-
- Otherwise, remove snapshots (starting from the oldest one) until the number of
- free space exceeds the given number of gigabytes.
- Use with caution!
-"