| 1 | John Taylor's patch for implementing --time-limit and --stop-at, reworked |
| 2 | to be simpler and more efficient by Wayne Davison. |
| 3 | |
| 4 | Do we need configure support for mktime() and strptime()? |
| 5 | |
| 6 | --- io.c 8 May 2004 18:03:43 -0000 1.120 |
| 7 | +++ io.c 8 May 2004 18:42:14 -0000 |
| 8 | @@ -44,6 +44,7 @@ static int io_multiplexing_in; |
| 9 | static int multiplex_in_fd = -1; |
| 10 | static int multiplex_out_fd = -1; |
| 11 | static time_t last_io; |
| 12 | +extern time_t stop_at_utime; |
| 13 | static int no_flush; |
| 14 | |
| 15 | extern int bwlimit; |
| 16 | @@ -125,15 +126,20 @@ static void check_timeout(void) |
| 17 | { |
| 18 | time_t t; |
| 19 | |
| 20 | - if (!io_timeout) |
| 21 | + if (!io_timeout && !stop_at_utime) |
| 22 | return; |
| 23 | |
| 24 | + t = time(NULL); |
| 25 | + |
| 26 | + if (stop_at_utime && t >= stop_at_utime) { |
| 27 | + rprintf(FERROR, "run-time limit exceeded\n"); |
| 28 | + exit_cleanup(RERR_TIMEOUT); |
| 29 | + } |
| 30 | + |
| 31 | if (!last_io) { |
| 32 | - last_io = time(NULL); |
| 33 | + last_io = t; |
| 34 | return; |
| 35 | } |
| 36 | - |
| 37 | - t = time(NULL); |
| 38 | |
| 39 | if (last_io && io_timeout && (t-last_io) >= io_timeout) { |
| 40 | if (!am_server && !am_daemon) { |
| 41 | --- options.c 6 May 2004 21:08:01 -0000 1.148 |
| 42 | +++ options.c 8 May 2004 18:42:14 -0000 |
| 43 | @@ -92,6 +92,7 @@ int modify_window = 0; |
| 44 | int blocking_io = -1; |
| 45 | int checksum_seed = 0; |
| 46 | unsigned int block_size = 0; |
| 47 | +time_t stop_at_utime = 0; |
| 48 | |
| 49 | |
| 50 | /** Network address family. **/ |
| 51 | @@ -288,6 +289,8 @@ void usage(enum logcode F) |
| 52 | rprintf(F," --log-format=FORMAT log file transfers using specified format\n"); |
| 53 | rprintf(F," --password-file=FILE get password from FILE\n"); |
| 54 | rprintf(F," --bwlimit=KBPS limit I/O bandwidth, KBytes per second\n"); |
| 55 | + rprintf(F," --stop-at=YY-MM-DD@HH:MM Stop rsync at year-month-day@hour:minute\n"); |
| 56 | + rprintf(F," --time-limit=TIME Stop rsync after TIME minutes have elapsed\n"); |
| 57 | rprintf(F," --write-batch=PREFIX write batch fileset starting with PREFIX\n"); |
| 58 | rprintf(F," --read-batch=PREFIX read batch fileset starting with PREFIX\n"); |
| 59 | #ifdef INET6 |
| 60 | @@ -305,7 +308,7 @@ void usage(enum logcode F) |
| 61 | enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM, |
| 62 | OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST, |
| 63 | OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, |
| 64 | - OPT_READ_BATCH, OPT_WRITE_BATCH, |
| 65 | + OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_STOP_AT, OPT_TIME_LIMIT, |
| 66 | OPT_REFUSED_BASE = 9000}; |
| 67 | |
| 68 | static struct poptOption long_options[] = { |
| 69 | @@ -377,6 +380,8 @@ static struct poptOption long_options[] |
| 70 | {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 }, |
| 71 | {"log-format", 0, POPT_ARG_STRING, &log_format, 0, 0, 0 }, |
| 72 | {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 }, |
| 73 | + {"stop-at", 0, POPT_ARG_STRING, 0, OPT_STOP_AT, 0, 0 }, |
| 74 | + {"time-limit", 0, POPT_ARG_STRING, 0, OPT_TIME_LIMIT, 0, 0 }, |
| 75 | {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 }, |
| 76 | {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 }, |
| 77 | {"hard-links", 'H', POPT_ARG_NONE, &preserve_hard_links, 0, 0, 0 }, |
| 78 | @@ -471,6 +476,7 @@ int parse_arguments(int *argc, const cha |
| 79 | { |
| 80 | int opt; |
| 81 | char *ref = lp_refuse_options(module_id); |
| 82 | + struct tm stop_at_tm; |
| 83 | const char *arg; |
| 84 | poptContext pc; |
| 85 | |
| 86 | @@ -584,6 +590,37 @@ int parse_arguments(int *argc, const cha |
| 87 | return 0; |
| 88 | #endif |
| 89 | |
| 90 | + case OPT_STOP_AT: |
| 91 | + arg = poptGetOptArg(pc); |
| 92 | + if (!strptime(arg, "%y-%m-%d@%H:%M", &stop_at_tm)) { |
| 93 | + snprintf(err_buf, sizeof err_buf, |
| 94 | + "invalid --stop-at format: %s\n", |
| 95 | + arg); |
| 96 | + rprintf(FERROR, "ERROR: %s", err_buf); |
| 97 | + return 0; |
| 98 | + } |
| 99 | + stop_at_utime = mktime(&stop_at_tm); |
| 100 | + if (stop_at_utime < time(NULL)) { |
| 101 | + snprintf(err_buf, sizeof err_buf, |
| 102 | + "--stop-at time is in the past: %s\n", |
| 103 | + arg); |
| 104 | + rprintf(FERROR, "ERROR: %s", err_buf); |
| 105 | + return 0; |
| 106 | + } |
| 107 | + break; |
| 108 | + |
| 109 | + case OPT_TIME_LIMIT: |
| 110 | + arg = poptGetOptArg(pc); |
| 111 | + if ((stop_at_utime = atol(arg) * 60) <= 0) { |
| 112 | + snprintf(err_buf, sizeof err_buf, |
| 113 | + "invalid --time-limit value: %s\n", |
| 114 | + arg); |
| 115 | + rprintf(FERROR, "ERROR: %s", err_buf); |
| 116 | + return 0; |
| 117 | + } |
| 118 | + stop_at_utime += time(NULL); |
| 119 | + break; |
| 120 | + |
| 121 | default: |
| 122 | /* A large opt value means that set_refuse_options() |
| 123 | * turned this option off (opt-BASE is its index). */ |
| 124 | @@ -881,6 +918,15 @@ void server_options(char **args,int *arg |
| 125 | |
| 126 | if (bwlimit) { |
| 127 | if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0) |
| 128 | + goto oom; |
| 129 | + args[ac++] = arg; |
| 130 | + } |
| 131 | + |
| 132 | + if (stop_at_utime) { |
| 133 | + long mins = (stop_at_utime - time(NULL)) / 60; |
| 134 | + if (mins <= 0) |
| 135 | + mins = 1; |
| 136 | + if (asprintf(&arg, "--time-limit=%ld", mins) < 0) |
| 137 | goto oom; |
| 138 | args[ac++] = arg; |
| 139 | } |
| 140 | --- rsync.yo 7 May 2004 00:18:37 -0000 1.169 |
| 141 | +++ rsync.yo 8 May 2004 18:42:15 -0000 |
| 142 | @@ -346,6 +346,8 @@ verb( |
| 143 | --log-format=FORMAT log file transfers using specified format |
| 144 | --password-file=FILE get password from FILE |
| 145 | --bwlimit=KBPS limit I/O bandwidth, KBytes per second |
| 146 | + --stop-at=YY-MM-DD@HH:MM Stop rsync at year-month-day@hour:minute |
| 147 | + --time-limit=TIME Stop rsync after TIME minutes have elapsed |
| 148 | --write-batch=PREFIX write batch fileset starting with PREFIX |
| 149 | --read-batch=PREFIX read batch fileset starting with PREFIX |
| 150 | -4 --ipv4 prefer IPv4 |
| 151 | @@ -890,6 +892,13 @@ of rsync transfers, blocks of data are s |
| 152 | transfer was too fast, it will wait before sending the next data block. The |
| 153 | result is an average transfer rate equaling the specified limit. A value |
| 154 | of zero specifies no limit. |
| 155 | + |
| 156 | +dit(bf(--stop-at=YY-MM-DD@HH:MM)) This option allows you to specify at what |
| 157 | +time to stop rsync, in year-month-day@hour:minute numeric format (e.g. |
| 158 | +04-12-3l@23:59). |
| 159 | + |
| 160 | +dit(bf(--time-limit=TIME)) This option allows you to specify the maximum |
| 161 | +number of minutes rsync will run for. |
| 162 | |
| 163 | dit(bf(--write-batch=PREFIX)) Generate a set of files that can be |
| 164 | transferred as a batch update. Each filename in the set starts with |