From 4f4c6b762372373e0ecb4c5f843ef1e010998eed Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Sat, 16 Mar 2019 08:37:39 +0300 Subject: [PATCH] [refer #PGPRO-1745] Add --remote-user option --- src/configure.c | 9 +++++++-- src/help.c | 24 ++++++++++++++---------- src/utils/remote.c | 4 ++++ src/utils/remote.h | 1 + 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/configure.c b/src/configure.c index 43b1f340..de245f40 100644 --- a/src/configure.c +++ b/src/configure.c @@ -195,12 +195,17 @@ ConfigOption instance_options[] = OPTION_REMOTE_GROUP, 0, option_get_value }, { - 's', 223, "ssh-options", + 's', 223, "remote-user", + &instance_config.remote.user, SOURCE_CMD, 0, + OPTION_REMOTE_GROUP, 0, option_get_value + }, + { + 's', 224, "ssh-options", &instance_config.remote.ssh_options, SOURCE_CMD, 0, OPTION_REMOTE_GROUP, 0, option_get_value }, { - 's', 224, "ssh-config", + 's', 225, "ssh-config", &instance_config.remote.ssh_config, SOURCE_CMD, 0, OPTION_REMOTE_GROUP, 0, option_get_value }, diff --git a/src/help.c b/src/help.c index da5aec05..a5ee373e 100644 --- a/src/help.c +++ b/src/help.c @@ -120,7 +120,7 @@ help_pg_probackup(void) printf(_(" [--replica-timeout=timeout]\n")); printf(_(" [--skip-block-validation]\n")); printf(_(" [--remote-proto] [--remote-host]\n")); - printf(_(" [--remote-port] [--remote-path]\n")); + printf(_(" [--remote-port] [--remote-path] [--remote-user]\n")); printf(_(" [--ssh-options]\n")); printf(_("\n %s restore -B backup-path --instance=instance_name\n"), PROGRAM_NAME); @@ -133,7 +133,7 @@ help_pg_probackup(void) printf(_(" [--no-validate]\n")); printf(_(" [--skip-block-validation]\n")); printf(_(" [--remote-proto] [--remote-host]\n")); - printf(_(" [--remote-port] [--remote-path]\n")); + printf(_(" [--remote-port] [--remote-path] [--remote-user]\n")); printf(_(" [--ssh-options]\n")); printf(_("\n %s validate -B backup-path [--instance=instance_name]\n"), PROGRAM_NAME); @@ -155,7 +155,7 @@ help_pg_probackup(void) printf(_("\n %s add-instance -B backup-path -D pgdata-path\n"), PROGRAM_NAME); printf(_(" --instance=instance_name\n")); printf(_(" [--remote-proto] [--remote-host]\n")); - printf(_(" [--remote-port] [--remote-path]\n")); + printf(_(" [--remote-port] [--remote-path] [--remote-user]\n")); printf(_(" [--ssh-options]\n")); printf(_("\n %s del-instance -B backup-path\n"), PROGRAM_NAME); @@ -169,14 +169,14 @@ help_pg_probackup(void) printf(_(" [--compress-level=compress-level]\n")); printf(_(" [--overwrite]\n")); printf(_(" [--remote-proto] [--remote-host]\n")); - printf(_(" [--remote-port] [--remote-path]\n")); + printf(_(" [--remote-port] [--remote-path] [--remote-user]\n")); printf(_(" [--ssh-options]\n")); printf(_("\n %s archive-get -B backup-path --instance=instance_name\n"), PROGRAM_NAME); printf(_(" --wal-file-path=wal-file-path\n")); printf(_(" --wal-file-name=wal-file-name\n")); printf(_(" [--remote-proto] [--remote-host]\n")); - printf(_(" [--remote-port] [--remote-path]\n")); + printf(_(" [--remote-port] [--remote-path] [--remote-user]\n")); printf(_(" [--ssh-options]\n")); if ((PROGRAM_URL || PROGRAM_EMAIL)) @@ -224,7 +224,7 @@ help_backup(void) printf(_(" [--replica-timeout=timeout]\n")); printf(_(" [--skip-block-validation]\n")); printf(_(" [--remote-proto] [--remote-host]\n")); - printf(_(" [--remote-port] [--remote-path]\n")); + printf(_(" [--remote-port] [--remote-path] [--remote-user]\n")); printf(_(" [--ssh-options]\n\n")); printf(_(" -B, --backup-path=backup-path location of the backup storage area\n")); @@ -298,6 +298,7 @@ help_backup(void) printf(_(" --remote-host=hostname remote host address or hostname\n")); printf(_(" --remote-port=port remote host port (default: 22)\n")); printf(_(" --remote-path=path path to pg_probackup binary on remote host (default: current binary path)\n")); + printf(_(" --remote-user=username user name for ssh connection (default current user)\n")); printf(_(" --ssh-options=ssh_options additional ssh options (default: none)\n")); } @@ -313,7 +314,7 @@ help_restore(void) printf(_(" [--restore-as-replica] [--no-validate]\n\n")); printf(_(" [--skip-block-validation]\n")); printf(_(" [--remote-proto] [--remote-host]\n")); - printf(_(" [--remote-port] [--remote-path]\n")); + printf(_(" [--remote-port] [--remote-path] [--remote-user]\n")); printf(_(" [--ssh-options]\n\n")); printf(_(" -B, --backup-path=backup-path location of the backup storage area\n")); @@ -370,6 +371,7 @@ help_restore(void) printf(_(" --remote-host=hostname remote host address or hostname\n")); printf(_(" --remote-port=port remote host port (default: 22)\n")); printf(_(" --remote-path=path path to pg_probackup binary on remote host (default: current binary path)\n")); + printf(_(" --remote-user=username user name for ssh connection (default current user)\n")); printf(_(" --ssh-options=ssh_options additional ssh options (default: none)\n")); } @@ -599,7 +601,7 @@ help_add_instance(void) printf(_("%s add-instance -B backup-path -D pgdata-path\n"), PROGRAM_NAME); printf(_(" --instance=instance_name\n")); printf(_(" [--remote-proto] [--remote-host]\n")); - printf(_(" [--remote-port] [--remote-path]\n")); + printf(_(" [--remote-port] [--remote-path] [--remote-user]\n")); printf(_(" [--ssh-options]\n\n")); printf(_(" -B, --backup-path=backup-path location of the backup storage area\n")); @@ -612,6 +614,7 @@ help_add_instance(void) printf(_(" --remote-host=hostname remote host address or hostname\n")); printf(_(" --remote-port=port remote host port (default: 22)\n")); printf(_(" --remote-path=path path to pg_probackup binary on remote host (default: current binary path)\n")); + printf(_(" --remote-user=username user name for ssh connection (default current user)\n")); printf(_(" --ssh-options=ssh_options additional ssh options (default: none)\n")); } @@ -635,7 +638,7 @@ help_archive_push(void) printf(_(" [--compress-level=compress-level]\n")); printf(_(" [--overwrite]\n")); printf(_(" [--remote-proto] [--remote-host]\n")); - printf(_(" [--remote-port] [--remote-path]\n")); + printf(_(" [--remote-port] [--remote-path] [--remote-user]\n")); printf(_(" [--ssh-options]\n\n")); printf(_(" -B, --backup-path=backup-path location of the backup storage area\n")); @@ -659,7 +662,7 @@ help_archive_get(void) printf(_(" --wal-file-path=wal-file-path\n")); printf(_(" --wal-file-name=wal-file-name\n")); printf(_(" [--remote-proto] [--remote-host]\n")); - printf(_(" [--remote-port] [--remote-path]\n")); + printf(_(" [--remote-port] [--remote-path] [--remote-user]\n")); printf(_(" [--ssh-options]\n\n")); printf(_(" -B, --backup-path=backup-path location of the backup storage area\n")); @@ -675,5 +678,6 @@ help_archive_get(void) printf(_(" --remote-host=hostname remote host address or hostname\n")); printf(_(" --remote-port=port remote host port (default: 22)\n")); printf(_(" --remote-path=path path to pg_probackup binary on remote host (default: current binary path)\n")); + printf(_(" --remote-user=username user name for ssh connection (default current user)\n")); printf(_(" --ssh-options=ssh_options additional ssh options (default: none)\n")); } diff --git a/src/utils/remote.c b/src/utils/remote.c index e3ecffeb..4228fd24 100644 --- a/src/utils/remote.c +++ b/src/utils/remote.c @@ -73,6 +73,10 @@ bool launch_agent(void) ssh_argv[ssh_argc++] = "-p"; ssh_argv[ssh_argc++] = instance_config.remote.port; } + if (instance_config.remote.user != NULL) { + ssh_argv[ssh_argc++] = "-l"; + ssh_argv[ssh_argc++] = instance_config.remote.user; + } if (instance_config.remote.ssh_config != NULL) { ssh_argv[ssh_argc++] = "-F"; ssh_argv[ssh_argc++] = instance_config.remote.ssh_config; diff --git a/src/utils/remote.h b/src/utils/remote.h index 6705a793..a0783671 100644 --- a/src/utils/remote.h +++ b/src/utils/remote.h @@ -16,6 +16,7 @@ typedef struct RemoteConfig char* host; char* port; char* path; + char* user; char *ssh_config; char *ssh_options; } RemoteConfig;