mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-05-03 20:42:50 -04:00
Add --bwlimit option contributed by Matthew Demicco and Jamie Gritton.
This commit is contained in:
15
io.c
15
io.c
@@ -27,6 +27,8 @@
|
||||
/* if no timeout is specified then use a 60 second select timeout */
|
||||
#define SELECT_TIMEOUT 60
|
||||
|
||||
extern int bwlimit;
|
||||
|
||||
static int io_multiplexing_out;
|
||||
static int io_multiplexing_in;
|
||||
static int multiplex_in_fd;
|
||||
@@ -388,6 +390,19 @@ static void writefd_unbuffered(int fd,char *buf,int len)
|
||||
exit_cleanup(RERR_STREAMIO);
|
||||
}
|
||||
|
||||
/* Sleep after writing to limit I/O bandwidth */
|
||||
if (bwlimit)
|
||||
{
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = ret * 1000 / bwlimit;
|
||||
while (tv.tv_usec > 1000000)
|
||||
{
|
||||
tv.tv_sec++;
|
||||
tv.tv_usec -= 1000000;
|
||||
}
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
}
|
||||
|
||||
total += ret;
|
||||
|
||||
if (io_timeout)
|
||||
|
||||
16
options.c
16
options.c
@@ -62,6 +62,7 @@ int safe_symlinks=0;
|
||||
int copy_unsafe_links=0;
|
||||
int block_size=BLOCK_SIZE;
|
||||
int size_only=0;
|
||||
int bwlimit=0;
|
||||
int delete_after=0;
|
||||
int only_existing=0;
|
||||
int max_delete=0;
|
||||
@@ -159,6 +160,7 @@ void usage(enum logcode F)
|
||||
rprintf(F," --progress show progress during transfer\n");
|
||||
rprintf(F," --log-format=FORMAT log file transfers using specified format\n");
|
||||
rprintf(F," --password-file=FILE get password from FILE\n");
|
||||
rprintf(F," --bwlimit=KBPS limit I/O bandwidth, KBytes per second\n");
|
||||
rprintf(F," -h, --help show this help screen\n");
|
||||
|
||||
rprintf(F,"\n");
|
||||
@@ -174,7 +176,7 @@ enum {OPT_VERSION, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE,
|
||||
OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST,
|
||||
OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS,
|
||||
OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR,
|
||||
OPT_IGNORE_ERRORS};
|
||||
OPT_IGNORE_ERRORS, OPT_BWLIMIT};
|
||||
|
||||
static char *short_options = "oblLWHpguDCtcahvqrRIxnSe:B:T:zP";
|
||||
|
||||
@@ -235,6 +237,7 @@ static struct option long_options[] = {
|
||||
{"config", 1, 0, OPT_CONFIG},
|
||||
{"port", 1, 0, OPT_PORT},
|
||||
{"log-format", 1, 0, OPT_LOG_FORMAT},
|
||||
{"bwlimit", 1, 0, OPT_BWLIMIT},
|
||||
{"address", 1, 0, OPT_ADDRESS},
|
||||
{"max-delete", 1, 0, OPT_MAX_DELETE},
|
||||
{"backup-dir", 1, 0, OPT_BACKUP_DIR},
|
||||
@@ -552,6 +555,10 @@ int parse_arguments(int argc, char *argv[], int frommain)
|
||||
case OPT_LOG_FORMAT:
|
||||
log_format = optarg;
|
||||
break;
|
||||
|
||||
case OPT_BWLIMIT:
|
||||
bwlimit = atoi(optarg);
|
||||
break;
|
||||
|
||||
case OPT_ADDRESS:
|
||||
{
|
||||
@@ -584,6 +591,8 @@ void server_options(char **args,int *argc)
|
||||
static char bsize[30];
|
||||
static char iotime[30];
|
||||
static char mdelete[30];
|
||||
static char bw[50];
|
||||
|
||||
int i, x;
|
||||
|
||||
args[ac++] = "--server";
|
||||
@@ -655,6 +664,11 @@ void server_options(char **args,int *argc)
|
||||
args[ac++] = iotime;
|
||||
}
|
||||
|
||||
if (bwlimit) {
|
||||
slprintf(bw,sizeof(bw),"--bwlimit=%d",bwlimit);
|
||||
args[ac++] = bw;
|
||||
}
|
||||
|
||||
if (strcmp(backup_suffix, BACKUP_SUFFIX)) {
|
||||
args[ac++] = "--suffix";
|
||||
args[ac++] = backup_suffix;
|
||||
|
||||
9
rsync.yo
9
rsync.yo
@@ -273,6 +273,7 @@ verb(
|
||||
--progress show progress during transfer
|
||||
--log-format=FORMAT log file transfers using specified format
|
||||
--password-file=FILE get password from FILE
|
||||
--bwlimit=KBPS limit I/O bandwidth, KBytes per second
|
||||
-h, --help show this help screen
|
||||
)
|
||||
|
||||
@@ -643,6 +644,14 @@ transport, not when using a remote shell as the transport. The file
|
||||
must not be world readable. It should contain just the password as a
|
||||
single line.
|
||||
|
||||
dit(bf(--bwlimit=KBPS)) This option allows you to specify a maximum
|
||||
transfer rate in kilobytes per second. This option is most effective when
|
||||
using rsync with large files (several megabytes and up). Due to the nature
|
||||
of rsync transfers, blocks of data are sent, then if rsync determines the
|
||||
transfer was too fast, it will wait before sending the next data block. The
|
||||
result is an average transfer rate equalling the specified limit. A value
|
||||
of zero specifies no limit.
|
||||
|
||||
enddit()
|
||||
|
||||
manpagesection(EXCLUDE PATTERNS)
|
||||
|
||||
Reference in New Issue
Block a user