The main code now excludes xattrs on devices for OS X.
[rsync-patches.git] / date-only.diff
1 Jeremy Bornstein wrote:
2
3 I recently had the need to transfer files only with different mod
4 dates (and to *not* transfer them based on file size differences).
5 This is because I'm backing up files remotely on an untrusted machine,
6 so I'm encrypting them with gpg before transfer.  I discovered that
7 rsync didn't already have a --date-only flag, so I added one and am
8 enclosing the diffs in case you (as I hope) decide to include this
9 option in future releases.
10
11 To use this patch, run these commands for a successful build:
12
13     patch -p1 <patches/date-only.diff
14     ./configure                                 (optional if already run)
15     make
16
17 based-on: d64bda1c1e79dc385f194d74f7957ce7cd118654
18 diff --git a/generator.c b/generator.c
19 --- a/generator.c
20 +++ b/generator.c
21 @@ -64,6 +64,7 @@ extern int append_mode;
22  extern int make_backups;
23  extern int csum_length;
24  extern int ignore_times;
25 +extern int date_only;
26  extern int size_only;
27  extern OFF_T max_size;
28  extern OFF_T min_size;
29 @@ -517,6 +518,9 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
30  /* Perform our quick-check heuristic for determining if a file is unchanged. */
31  int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
32  {
33 +       if (date_only)
34 +               return cmp_time(st->st_mtime, file->modtime) == 0;
35 +
36         if (st->st_size != F_LENGTH(file))
37                 return 0;
38  
39 diff --git a/options.c b/options.c
40 --- a/options.c
41 +++ b/options.c
42 @@ -105,6 +105,7 @@ int safe_symlinks = 0;
43  int copy_unsafe_links = 0;
44  int munge_symlinks = 0;
45  int size_only = 0;
46 +int date_only = 0;
47  int daemon_bwlimit = 0;
48  int bwlimit = 0;
49  int fuzzy_basis = 0;
50 @@ -742,6 +743,7 @@ void usage(enum logcode F)
51    rprintf(F," -I, --ignore-times          don't skip files that match in size and mod-time\n");
52    rprintf(F," -M, --remote-option=OPTION  send OPTION to the remote side only\n");
53    rprintf(F,"     --size-only             skip files that match in size\n");
54 +  rprintf(F,"     --date-only             skip files that match in mod-time\n");
55    rprintf(F,"     --modify-window=NUM     compare mod-times with reduced accuracy\n");
56    rprintf(F," -T, --temp-dir=DIR          create temporary files in directory DIR\n");
57    rprintf(F," -y, --fuzzy                 find similar file for basis if no dest file\n");
58 @@ -893,6 +895,7 @@ static struct poptOption long_options[] = {
59    {"chmod",            0,  POPT_ARG_STRING, 0, OPT_CHMOD, 0, 0 },
60    {"ignore-times",    'I', POPT_ARG_NONE,   &ignore_times, 0, 0, 0 },
61    {"size-only",        0,  POPT_ARG_NONE,   &size_only, 0, 0, 0 },
62 +  {"date-only",        0,  POPT_ARG_NONE,   &date_only, 0, 0, 0 },
63    {"one-file-system", 'x', POPT_ARG_NONE,   0, 'x', 0, 0 },
64    {"no-one-file-system",0, POPT_ARG_VAL,    &one_file_system, 0, 0, 0 },
65    {"no-x",             0,  POPT_ARG_VAL,    &one_file_system, 0, 0, 0 },
66 @@ -2558,6 +2561,9 @@ void server_options(char **args, int *argc_p)
67         else if (missing_args == 1 && !am_sender)
68                 args[ac++] = "--ignore-missing-args";
69  
70 +       if (date_only)
71 +               args[ac++] = "--date-only";
72 +
73         if (modify_window_set) {
74                 if (asprintf(&arg, "--modify-window=%d", modify_window) < 0)
75                         goto oom;
76 diff --git a/rsync.yo b/rsync.yo
77 --- a/rsync.yo
78 +++ b/rsync.yo
79 @@ -395,6 +395,7 @@ to the detailed description below for a complete description.  verb(
80       --contimeout=SECONDS    set daemon connection timeout in seconds
81   -I, --ignore-times          don't skip files that match size and time
82       --size-only             skip files that match in size
83 +     --date-only             skip files that match in mod-time
84       --modify-window=NUM     compare mod-times with reduced accuracy
85   -T, --temp-dir=DIR          create temporary files in directory DIR
86   -y, --fuzzy                 find similar file for basis if no dest file
87 @@ -555,6 +556,12 @@ time to just looking for files that have changed in size.  This is useful
88  when starting to use rsync after using another mirroring system which may
89  not preserve timestamps exactly.
90  
91 +dit(bf(--date-only)) Normally rsync will skip any files that are
92 +already the same size and have the same modification time-stamp. With the
93 +--date-only option, files will be skipped if they have the same
94 +timestamp, regardless of size. This may be useful when the remote
95 +files have passed through a size-changing filter, e.g. for encryption.
96 +
97  dit(bf(--modify-window)) When comparing two timestamps, rsync treats the
98  timestamps as being equal if they differ by no more than the modify-window
99  value.  This is normally 0 (for an exact match), but you may find it useful