I've added the options --min-age=SECONDS and --max-age=SECONDS to allow rsync to skip files based on how recently they were modified.

Setting --min-age=30 (for example) would cause rsync to skip files that had been modified within the last 30 seconds.

Setting --max-age=7776000 would cause rsync to skip files that had been modified more than 90 days ago (7776000 == 60*60*24*90).

I realize some of this could be achieved with a find command and --exclude-from, but the same could be said for --min-size/--max-size. But it's more convenient to have these options, and they would allow for things --exclude-from wouldn't. For example, a file might've been modified after generating the exclude file, so rsync would still transfer it even though that wasn't what was wanted.





diff --git a/generator.c b/generator.c
index 110db28f..22f0973f 100644
--- a/generator.c
+++ b/generator.c
@@ -70,6 +70,8 @@ extern int ignore_times;
 extern int size_only;
 extern OFF_T max_size;
 extern OFF_T min_size;
+extern int max_age;
+extern int min_age;
 extern int io_error;
 extern int flist_eof;
 extern int allowed_lull;
@@ -1706,6 +1708,23 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                goto cleanup;
        }

+       if (max_age > 0 && time(NULL)-file->modtime > max_age) {
+               if (INFO_GTE(SKIP, 1)) {
+                       if (solo_file)
+                               fname = f_name(file, NULL);
+                       rprintf(FINFO, "%s is over max-age\n", fname);
+               }
+               goto cleanup;
+       }
+       if (min_age > 0 && time(NULL)-file->modtime < min_age) {
+               if (INFO_GTE(SKIP, 1)) {
+                       if (solo_file)
+                               fname = f_name(file, NULL);
+                       rprintf(FINFO, "%s is under min-age\n", fname);
+               }
+               goto cleanup;
+       }
+
if (update_only > 0 && statret == 0 && file->modtime - sx.st.st_mtime < modify_window) {
                if (INFO_GTE(SKIP, 1))
                        rprintf(FINFO, "%s is newer\n", fname);
@@ -2156,9 +2175,13 @@ void check_for_finished_files(int itemizing, enum logcode code, int check_redo)
                if (check_redo && (ndx = get_redo_num()) != -1) {
                        OFF_T save_max_size = max_size;
                        OFF_T save_min_size = min_size;
+                       int save_max_age = max_age;
+                       int save_min_age = min_age;
                        csum_length = SUM_LENGTH;
                        max_size = -1;
                        min_size = -1;
+                       max_age = 0;
+                       min_age = 0;
                        ignore_existing = -ignore_existing;
                        ignore_non_existing = -ignore_non_existing;
                        update_only = -update_only;
@@ -2184,6 +2207,8 @@ void check_for_finished_files(int itemizing, enum logcode code, int check_redo)
                        csum_length = SHORT_SUM_LENGTH;
                        max_size = save_max_size;
                        min_size = save_min_size;
+                       max_age = save_max_age;
+                       min_age = save_min_age;
                        ignore_existing = -ignore_existing;
                        ignore_non_existing = -ignore_non_existing;
                        update_only = -update_only;
diff --git a/options.c b/options.c
index fd674754..7c7f31db 100644
--- a/options.c
+++ b/options.c
@@ -129,6 +129,8 @@ int need_messages_from_generator = 0;
 int max_delete = INT_MIN;
 OFF_T max_size = -1;
 OFF_T min_size = -1;
+int max_age = 0;
+int min_age = 0;
 int ignore_errors = 0;
 int modify_window = 0;
 int blocking_io = -1;
@@ -698,6 +700,8 @@ static struct poptOption long_options[] = {
   {"ignore-existing",  0,  POPT_ARG_NONE,   &ignore_existing, 0, 0, 0 },
{"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 }, {"min-size", 0, POPT_ARG_STRING, &min_size_arg, OPT_MIN_SIZE, 0, 0 },
+  {"max-age",         0,  POPT_ARG_INT, &max_age, 0, 0, 0 },
+  {"min-age",         0,  POPT_ARG_INT, &min_age, 0, 0, 0 },
   {"max-alloc",        0,  POPT_ARG_STRING, &max_alloc_arg, 0, 0, 0 },
   {"sparse",          'S', POPT_ARG_VAL,    &sparse_files, 1, 0, 0 },
   {"no-sparse",        0,  POPT_ARG_VAL,    &sparse_files, 0, 0, 0 },
@@ -2815,6 +2819,16 @@ void server_options(char **args, int *argc_p)
                        args[ac++] = safe_arg("--min-size", min_size_arg);
                if (max_size >= 0)
                        args[ac++] = safe_arg("--max-size", max_size_arg);
+               if (min_age > 0) {
+                       if (asprintf(&arg, "--min-age=%d", min_age) < 0)
+                               goto oom;
+                       args[ac++] = arg;
+               }
+               if (max_age > 0) {
+                       if (asprintf(&arg, "--max-age=%d", max_age) < 0)
+                               goto oom;
+                       args[ac++] = arg;
+               }
                if (delete_before)
                        args[ac++] = "--delete-before";
                else if (delete_during == 2)
diff --git a/rsync.1.md b/rsync.1.md
index 2ae6f481..66dba8c3 100644
--- a/rsync.1.md
+++ b/rsync.1.md
@@ -491,6 +491,8 @@ has its own detailed description later in this manpage.
 --max-delete=NUM         don't delete more than NUM files
 --max-size=SIZE          don't transfer any file larger than SIZE
 --min-size=SIZE          don't transfer any file smaller than SIZE
+--max-age=SECONDS        don't transfer file if mtime > SECONDS ago
+--min-age=SECONDS        don't transfer file if mtime < SECONDS ago
 --max-alloc=SIZE         change a limit relating to memory alloc
 --partial                keep partially transferred files
 --partial-dir=DIR        put a partially transferred file into DIR
@@ -2090,6 +2092,22 @@ expand it.

     Note that rsync versions prior to 3.1.0 did not allow `--min-size=0`.

+0.  `--max-age=SECONDS`
+
+ This tells rsync to avoid transferring any file that has a modifiction time
+    greater than the specified number of SECONDS ago.
+
+    This option is a [TRANSFER RULE](#TRANSFER_RULES), so don't expect any
+    exclude side effects.
+
+0.  `--min-age=SECONDS`
+
+ This tells rsync to avoid transferring any file that has a modifiction time
+    less than the specified number of SECONDS ago.
+
+    This option is a [TRANSFER RULE](#TRANSFER_RULES), so don't expect any
+    exclude side effects.
+
 0.  `--max-alloc=SIZE`

By default rsync limits an individual malloc/realloc to about 1GB in size.

--
Please use reply-all for most replies to avoid omitting the mailing list.
To unsubscribe or change options: https://lists.samba.org/mailman/listinfo/rsync
Before posting, read: http://www.catb.org/~esr/faqs/smart-questions.html

Reply via email to