!656 gs_basebackup添加timeout参数

Merge pull request !656 from wangrui/master
This commit is contained in:
opengauss-bot
2021-02-05 16:12:32 +08:00
committed by Gitee
3 changed files with 23 additions and 2 deletions

View File

@ -205,6 +205,8 @@ static void usage(void)
printf(_(" -F, --format=p|t output format (plain (default), tar)\n"));
printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"
" relocate tablespace in OLDDIR to NEWDIR\n"));
printf(_(" -t, --rw_timeout=TIME rw_timeout limit\n"
" the value range from 60 to 3600 (s) (default 120s)\n"));
printf(_(" -x, --xlog include required WAL files in backup (fetch mode)\n"));
printf(_(" -X, --xlog-method=fetch|stream\n"
" include required WAL files with specified method\n"));
@ -1855,6 +1857,7 @@ static int GsBaseBackup(int argc, char** argv)
{"format", required_argument, NULL, 'F'},
{"checkpoint", required_argument, NULL, 'c'},
{"tablespace-mapping", required_argument, NULL, 'T'},
{"rw_timeout", required_argument, NULL, 't'},
{"xlog", no_argument, NULL, 'x'},
{"xlog-method", required_argument, NULL, 'X'},
{"gzip", no_argument, NULL, 'z'},
@ -1884,7 +1887,7 @@ static int GsBaseBackup(int argc, char** argv)
}
}
while ((c = getopt_long(argc, argv, "D:l:c:h:p:U:s:X:F:T:Z:wWvPxz", long_options, &option_index)) != -1) {
while ((c = getopt_long(argc, argv, "D:l:c:h:p:U:s:X:F:T:t:Z:wWvPxz", long_options, &option_index)) != -1) {
switch (c) {
case 'D': {
GS_FREE(basedir);
@ -1918,6 +1921,22 @@ static int GsBaseBackup(int argc, char** argv)
}
tablespace_list_append(optarg);
break;
case 't': {
/* set length limit for preventing para out of int range */
if (strspn(optarg, "0123456789") != strlen(optarg) || strlen(optarg) > 4) {
fprintf(stderr, _("%s: invalid value:%s\n"), progname, optarg);
exit(1);
}
int baseBackupPara = atoi(optarg);
/* the timeout range is between 1min and 60mins */
if (baseBackupPara < 60 || baseBackupPara > 3600) {
fprintf(stderr, _("%s: invalid value:%s\n"), progname, optarg);
exit(1);
}
baseBackupTimeout = xstrdup(optarg);
break;
}
case 'x':
streamwal = false;
break;

View File

@ -31,6 +31,7 @@ char* dbhost = NULL;
char* dbuser = NULL;
char* dbport = NULL;
char* dbname = NULL;
char* baseBackupTimeout = "120"; /* default value */
int dbgetpassword = 0; /* 0=auto, -1=never, 1=always */
static char* dbpassword = NULL;
PGconn* conn = NULL;
@ -165,7 +166,7 @@ PGconn* GetConnection(void)
keywords[3] = "connect_timeout"; /* param connect_time */
values[3] = "120"; /* default connect_time */
keywords[4] = "rw_timeout"; /* param rw_timeout */
values[4] = "120"; /* default rw_timeout */
values[4] = baseBackupTimeout; /* value rw_timeout */
int i = 5;
if (dbhost != NULL) {
keywords[i] = "host";

View File

@ -8,6 +8,7 @@ extern char* dbhost;
extern char* dbuser;
extern char* dbport;
extern char* dbname;
extern char* baseBackupTimeout;
extern int dbgetpassword;
extern char* replication_slot;
extern int standby_message_timeout;