Skip to content

Commit

Permalink
Add --retry-forever option.
Browse files Browse the repository at this point in the history
This option, if set, causes tarsnap to continue trying to reconnect to
the tarsnap server forever, instead of giving up after 5-10 minutes.
This option may be useful for people with excessively flaky networks
or on mobile devices which regularly lose their internet connections
for extended periods of time; it will however not be turned on by
default since the combination of a network (mis)configuration which
breaks tarsnap and a system administrator who does not verify that
backups have completed could result in a tarsnap process "lingering"
for an extended period of time without overtly failing.

This option has not been added to the tarsnap man page yet.  That
should happen before the next release.
  • Loading branch information
cperciva committed Jul 10, 2015
1 parent a855b78 commit c5d4a51
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/netpacket/netpacket_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ static int reconnect_wait[MAXRECONNECTS + 1] = {
0, 0, 1, 2, 4, 8, 15, 30, 60, 90, 90
};

/* Global tarsnap option declared in tarsnap_opt.h. */
int tarsnap_opt_retry_forever = 0;

/* Time before which we shouldn't print a "connection lost" warning. */
static struct timeval next_connlost_warning = { 0, 0};

Expand Down Expand Up @@ -241,6 +244,8 @@ reconnect(NETPACKET_CONNECTION * NPC)

/* Have we lost our connection / failed to connect too many times? */
NPC->ndrops += 1;
if (tarsnap_opt_retry_forever && NPC->ndrops > MAXRECONNECTS)
NPC->ndrops = MAXRECONNECTS;
if ((NPC->ndrops > MAXRECONNECTS) ||
(NPC->serveralive == 0 && NPC->ndrops > MAXRECONNECTS_AWOL)) {
warn0("Too many network failures");
Expand Down
17 changes: 17 additions & 0 deletions tar/bsdtar.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ main(int argc, char **argv)
case OPTION_NO_QUIET:
optq_push(bsdtar, "no-quiet", NULL);
break;
case OPTION_NO_RETRY_FOREVER:
optq_push(bsdtar, "no-retry-forever", NULL);
break;
case OPTION_NO_SAME_OWNER: /* GNU tar */
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_OWNER;
break;
Expand Down Expand Up @@ -531,6 +534,9 @@ main(int argc, char **argv)
case OPTION_RECOVER:
set_mode(bsdtar, opt, "--recover");
break;
case OPTION_RETRY_FOREVER:
optq_push(bsdtar, "retry-forever", NULL);
break;
case OPTION_SNAPTIME: /* multitar */
optq_push(bsdtar, "snaptime", bsdtar->optarg);
break;
Expand Down Expand Up @@ -1448,6 +1454,11 @@ dooption(struct bsdtar *bsdtar, const char * conf_opt,
goto optset;

bsdtar->option_quiet_set = 1;
} else if (strcmp(conf_opt, "no-retry-forever") == 0) {
if (bsdtar->option_retry_forever_set)
goto optset;

bsdtar->option_retry_forever_set = 1;
} else if (strcmp(conf_opt, "no-snaptime") == 0) {
if (bsdtar->option_snaptime_set)
goto optset;
Expand Down Expand Up @@ -1477,6 +1488,12 @@ dooption(struct bsdtar *bsdtar, const char * conf_opt,

bsdtar->option_quiet = 1;
bsdtar->option_quiet_set = 1;
} else if (strcmp(conf_opt, "retry-forever") == 0) {
if (bsdtar->option_retry_forever_set)
goto optset;

tarsnap_opt_retry_forever = 1;
bsdtar->option_retry_forever_set = 1;
} else if (strcmp(conf_opt, "snaptime") == 0) {
if (bsdtar->mode != 'c')
goto badmode;
Expand Down
3 changes: 3 additions & 0 deletions tar/bsdtar.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ struct bsdtar {
int option_no_config_include_set;
int option_quiet;
int option_quiet_set;
int option_retry_forever_set;
int option_insane_filesystems;
int option_insane_filesystems_set;
const char **configfiles; /* --configfile */
Expand Down Expand Up @@ -199,6 +200,7 @@ enum {
OPTION_NO_NODUMP,
OPTION_NO_PRINT_STATS,
OPTION_NO_QUIET,
OPTION_NO_RETRY_FOREVER,
OPTION_NO_SAME_OWNER,
OPTION_NO_SAME_PERMISSIONS,
OPTION_NO_SNAPTIME,
Expand All @@ -214,6 +216,7 @@ enum {
OPTION_RECOVER,
OPTION_RECOVER_DELETE, /* Operation mode, not a real option */
OPTION_RECOVER_WRITE, /* Operation mode, not a real option */
OPTION_RETRY_FOREVER,
OPTION_QUIET,
OPTION_SNAPTIME,
OPTION_STORE_ATIME,
Expand Down
2 changes: 2 additions & 0 deletions tar/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ static struct option {
{ "no-print-stats", 0, OPTION_NO_PRINT_STATS },
{ "no-quiet", 0, OPTION_NO_QUIET },
{ "no-recursion", 0, 'n' },
{ "no-retry-forever", 0, OPTION_NO_RETRY_FOREVER },
{ "no-same-owner", 0, OPTION_NO_SAME_OWNER },
{ "no-same-permissions", 0, OPTION_NO_SAME_PERMISSIONS },
{ "no-snaptime", 0, OPTION_NO_SNAPTIME },
Expand All @@ -144,6 +145,7 @@ static struct option {
{ "quiet", 0, OPTION_QUIET },
{ "read-full-blocks", 0, 'B' },
{ "recover", 0, OPTION_RECOVER },
{ "retry-forever", 0, OPTION_RETRY_FOREVER },
{ "same-owner", 0, OPTION_SAME_OWNER },
{ "same-permissions", 0, 'p' },
{ "snaptime", 1, OPTION_SNAPTIME },
Expand Down
3 changes: 3 additions & 0 deletions tar/tarsnap_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
/* Use multiple TCP connections when writing an archive. */
extern int tarsnap_opt_aggressive_networking;

/* Keep trying forever if connection lost. */
extern int tarsnap_opt_retry_forever;

/* Print statistics using "human-readable" SI prefixes. */
extern int tarsnap_opt_humanize_numbers;

Expand Down

0 comments on commit c5d4a51

Please sign in to comment.