1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-02-03 14:01:57 +02:00

Add -ssh-options option

This commit is contained in:
Konstantin Knizhnik 2018-11-27 11:19:49 +03:00
parent 50cb6f7893
commit c64fd5a43e
3 changed files with 52 additions and 6 deletions

View File

@ -78,6 +78,7 @@ char *remote_host;
char *remote_port; char *remote_port;
char *remote_proto = (char*)"ssh"; char *remote_proto = (char*)"ssh";
char *ssh_config; char *ssh_config;
char *ssh_options;
bool is_remote_agent; bool is_remote_agent;
bool is_remote_backup; bool is_remote_backup;
@ -178,8 +179,9 @@ static pgut_option options[] =
{ 's', 20, "remote-port", &remote_port, SOURCE_CMDLINE, }, { 's', 20, "remote-port", &remote_port, SOURCE_CMDLINE, },
{ 's', 21, "remote-proto", &remote_proto, SOURCE_CMDLINE, }, { 's', 21, "remote-proto", &remote_proto, SOURCE_CMDLINE, },
{ 's', 22, "ssh-config", &ssh_config, SOURCE_CMDLINE, }, { 's', 22, "ssh-config", &ssh_config, SOURCE_CMDLINE, },
{ 'b', 23, "agent", &is_remote_agent, SOURCE_CMDLINE, }, { 's', 23, "ssh-options", &ssh_options, SOURCE_CMDLINE, },
{ 'b', 24, "remote", &is_remote_backup, SOURCE_CMDLINE, }, { 'b', 24, "agent", &is_remote_agent, SOURCE_CMDLINE, },
{ 'b', 25, "remote", &is_remote_backup, SOURCE_CMDLINE, },
/* restore options */ /* restore options */
{ 's', 30, "time", &target_time, SOURCE_CMDLINE }, { 's', 30, "time", &target_time, SOURCE_CMDLINE },
{ 's', 31, "xid", &target_xid, SOURCE_CMDLINE }, { 's', 31, "xid", &target_xid, SOURCE_CMDLINE },

View File

@ -357,6 +357,7 @@ extern char *remote_port;
extern char *remote_host; extern char *remote_host;
extern char *remote_proto; extern char *remote_proto;
extern char *ssh_config; extern char *ssh_config;
extern char *ssh_options;
extern const char *master_db; extern const char *master_db;
extern const char *master_host; extern const char *master_host;
extern const char *master_port; extern const char *master_port;

View File

@ -8,6 +8,7 @@
#include "file.h" #include "file.h"
#define MAX_CMDLINE_LENGTH 4096 #define MAX_CMDLINE_LENGTH 4096
#define MAX_CMDLINE_OPTIONS 256
static int append_option(char* buf, size_t buf_size, size_t dst, char const* src) static int append_option(char* buf, size_t buf_size, size_t dst, char const* src)
{ {
@ -21,11 +22,50 @@ static int append_option(char* buf, size_t buf_size, size_t dst, char const* src
return dst + len + 1; return dst + len + 1;
} }
static int split_options(int argc, char* argv[], int max_options, char* options)
{
char* opt = options;
char in_quote = '\0';
while (true) {
switch (*opt) {
case '\'':
case '\"':
if (!in_quote) {
in_quote = *opt++;
continue;
}
if (*opt == in_quote && *++opt != in_quote) {
in_quote = '\0';
continue;
}
break;
case '\0':
if (opt != options) {
argv[argc++] = options;
if (argc >= max_options)
elog(ERROR, "Too much options");
}
return argc;
case ' ':
argv[argc++] = options;
if (argc >= max_options)
elog(ERROR, "Too much options");
*opt++ = '\0';
options = opt;
continue;
default:
break;
}
opt += 1;
}
return argc;
}
int remote_execute(int argc, char* argv[], bool listen) int remote_execute(int argc, char* argv[], bool listen)
{ {
char cmd[MAX_CMDLINE_LENGTH]; char cmd[MAX_CMDLINE_LENGTH];
size_t dst = 0; size_t dst = 0;
char* ssh_argv[8]; char* ssh_argv[MAX_CMDLINE_OPTIONS];
int ssh_argc; int ssh_argc;
int i; int i;
int outfd[2]; int outfd[2];
@ -34,14 +74,17 @@ int remote_execute(int argc, char* argv[], bool listen)
ssh_argc = 0; ssh_argc = 0;
ssh_argv[ssh_argc++] = remote_proto; ssh_argv[ssh_argc++] = remote_proto;
if (remote_port != 0) { if (remote_port != NULL) {
ssh_argv[ssh_argc++] = (char*)"-p"; ssh_argv[ssh_argc++] = (char*)"-p";
ssh_argv[ssh_argc++] = remote_port; ssh_argv[ssh_argc++] = remote_port;
} }
if (ssh_config != 0) { if (ssh_config != NULL) {
ssh_argv[ssh_argc++] = (char*)"-F"; ssh_argv[ssh_argc++] = (char*)"-F";
ssh_argv[ssh_argc++] = ssh_config; ssh_argv[ssh_argc++] = ssh_config;
} }
if (ssh_options != NULL) {
ssh_argc = split_options(ssh_argc, ssh_argv, MAX_CMDLINE_OPTIONS, ssh_options);
}
ssh_argv[ssh_argc++] = remote_host; ssh_argv[ssh_argc++] = remote_host;
ssh_argv[ssh_argc++] = cmd+1; ssh_argv[ssh_argc++] = cmd+1;
ssh_argv[ssh_argc] = NULL; ssh_argv[ssh_argc] = NULL;