From: Andre Noll Date: Mon, 17 Apr 2017 17:06:37 +0000 (+0200) Subject: Implement --checksum. X-Git-Tag: v1.0.0~25^2~4 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=b01b9e2b9d8e63ea13119096dceb19f436aef544;p=dss.git Implement --checksum. It is considered good practice to run rsync with --checksum from time to time. This patch implements the feature via the new --checksum option. The probabilistic approach was chosen so that dss does not need to remember which snapshots were created with --checksum. --- diff --git a/dss.c b/dss.c index 5e2ef46..3e626ab 100644 --- a/dss.c +++ b/dss.c @@ -1347,6 +1347,7 @@ static void create_rsync_argv(char ***argv, int64_t *num) char *logname; int i = 0, j, N = OPT_GIVEN(DSS, RSYNC_OPTION); struct snapshot_list sl; + static bool seeded; dss_get_snapshot_list(&sl); assert(!name_of_reference_snapshot); @@ -1357,6 +1358,14 @@ static void create_rsync_argv(char ***argv, int64_t *num) (*argv)[i++] = dss_strdup("rsync"); (*argv)[i++] = dss_strdup("-a"); (*argv)[i++] = dss_strdup("--delete"); + if (!seeded) { + srandom((unsigned)time(NULL)); /* no need to be fancy here */ + seeded = true; + } + if (1000 * (random() / (RAND_MAX + 1.0)) < OPT_UINT32_VAL(DSS, CHECKSUM)) { + DSS_NOTICE_LOG(("adding --checksum to rsync options\n")); + (*argv)[i++] = dss_strdup("--checksum"); + } for (j = 0; j < N; j++) (*argv)[i++] = dss_strdup(lls_string_val(j, OPT_RESULT(DSS, RSYNC_OPTION))); diff --git a/dss.suite b/dss.suite index e7473cb..e69cc28 100644 --- a/dss.suite +++ b/dss.suite @@ -109,6 +109,29 @@ caption = Subcommands Set this if the user that runs dss is different from the user on the remote host. [/help] + [option checksum] + summary = run rsync with --checksum occasionally + typestr = permille + arg_info = required_arg + arg_type = uint32 + default_val = 0 + [help] + If a file on the backup becomes corrupt in a way that file size + and modification time still match the original file, rsync will not + consider the file for transfer ("quick check"). Hence the corruption + stays on the backup until the file is modified on the source. + The --checksum option of rsync disables the quick check and compares + the contents of each file, fixing such corruptions. Since computing + the checksums adds a significant slowdown due to a lot of disk I/O, + the option is not enabled by default. + + The argument to the --checksum option of dss is a number between 0 + and 1000, inclusively, which determines the probability of adding + --checksum to the rsync options each time a snapshot is created. The + default value zero means to never add the option. The value 100 will + create every tenth snapshot (on average) using checksums, and the + value 1000 will always pass --checksum to rsync. + [/help] [option rsync-option] short_opt = O summary = further rsync options