From 80e06757ad035c45f957ca97e4aa72b142df232e Mon Sep 17 00:00:00 2001 From: zhang_xubo <2578876417@qq.com> Date: Tue, 4 Jan 2022 22:06:56 +0800 Subject: [PATCH] =?UTF-8?q?gs=5Fprobackup=E8=BF=9C=E7=A8=8B=E5=A4=87?= =?UTF-8?q?=E4=BB=BD=E4=B8=94=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E5=88=86?= =?UTF-8?q?=E7=A6=BB=E4=B8=8B=EF=BC=8C=E5=8A=A0=E8=BD=BD=E4=B8=8D=E5=88=B0?= =?UTF-8?q?lib=E5=BA=93=E3=80=82=E5=A2=9E=E5=8A=A0=20--remote-libpath?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_probackup/configure.cpp | 9 +++++++++ src/bin/pg_probackup/init.cpp | 2 ++ src/bin/pg_probackup/remote.cpp | 30 ++++++++++++++++++++++-------- src/bin/pg_probackup/remote.h | 1 + 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_probackup/configure.cpp b/src/bin/pg_probackup/configure.cpp index 24f977690..bf49c5c42 100644 --- a/src/bin/pg_probackup/configure.cpp +++ b/src/bin/pg_probackup/configure.cpp @@ -215,6 +215,11 @@ ConfigOption instance_options[] = &instance_config.remote.ssh_config, SOURCE_CMD, (OptionSource)0, OPTION_REMOTE_GROUP, 0, option_get_value }, + { + 's', 231, "remote-libpath", + &instance_config.remote.libpath, SOURCE_CMD, (OptionSource)0, + OPTION_REMOTE_GROUP, 0, option_get_value + }, { 0 } }; @@ -506,6 +511,10 @@ readInstanceConfigFile(const char *instance_name) 's', 230, "ssh-config", &instance->remote.ssh_config, SOURCE_CMD, (OptionSource)0, OPTION_REMOTE_GROUP, 0, option_get_value }, + { + 's', 231, "remote-libpath", &instance->remote.libpath, SOURCE_CMD, (OptionSource)0, + OPTION_REMOTE_GROUP, 0, option_get_value + }, { 0 } }; diff --git a/src/bin/pg_probackup/init.cpp b/src/bin/pg_probackup/init.cpp index a211152e1..2fb8fd8e1 100644 --- a/src/bin/pg_probackup/init.cpp +++ b/src/bin/pg_probackup/init.cpp @@ -116,6 +116,8 @@ do_add_instance(InstanceConfig *instance) SOURCE_DEFAULT); config_set_opt(instance_options, &instance_config.remote.path, SOURCE_DEFAULT); + config_set_opt(instance_options, &instance_config.remote.libpath, + SOURCE_DEFAULT); config_set_opt(instance_options, &instance_config.remote.user, SOURCE_DEFAULT); config_set_opt(instance_options, &instance_config.remote.ssh_options, diff --git a/src/bin/pg_probackup/remote.cpp b/src/bin/pg_probackup/remote.cpp index 95937cce3..0db9ea33e 100644 --- a/src/bin/pg_probackup/remote.cpp +++ b/src/bin/pg_probackup/remote.cpp @@ -113,6 +113,7 @@ bool launch_agent(void) { char cmd[MAX_CMDLINE_LENGTH]; char* ssh_argv[MAX_CMDLINE_OPTIONS]; + char libenv[MAX_CMDLINE_LENGTH] = {0}; int ssh_argc; int outfd[2]; int infd[2]; @@ -156,6 +157,19 @@ bool launch_agent(void) ssh_argv[ssh_argc++] = (char *)cmd; ssh_argv[ssh_argc] = NULL; + if (instance_config.remote.libpath) + { +#ifdef WIN32 + rc = snprintf_s(libenv, sizeof(libenv), sizeof(libenv) - 1, "set LD_LIBRARY_PATH=%s &&", + instance_config.remote.libpath); + securec_check_ss_c(rc, "\0", "\0"); +#else + rc = snprintf_s(libenv, sizeof(libenv), sizeof(libenv) - 1, "export LD_LIBRARY_PATH=%s &&", + instance_config.remote.libpath); + securec_check_ss_c(rc, "\0", "\0"); +#endif + } + if (instance_config.remote.path) { char const* probackup = PROGRAM_NAME_FULL; @@ -172,27 +186,27 @@ bool launch_agent(void) } if (needs_quotes(instance_config.remote.path) || needs_quotes(PROGRAM_NAME_FULL)) { - rc = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "\"%s\\%s\" agent", - instance_config.remote.path, probackup); + rc = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "\"%s %s\\%s\" agent", + libenv, instance_config.remote.path, probackup); securec_check_ss_c(rc, "\0", "\0"); } else { - rc = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "%s\\%s agent", - instance_config.remote.path, probackup); + rc = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "%s %s\\%s agent", + libenv, instance_config.remote.path, probackup); securec_check_ss_c(rc, "\0", "\0"); } #else if (needs_quotes(instance_config.remote.path) || needs_quotes(PROGRAM_NAME_FULL)) { - rc = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "\"%s/%s\" agent", - instance_config.remote.path, probackup); + rc = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "\"%s %s/%s\" agent", + libenv, instance_config.remote.path, probackup); securec_check_ss_c(rc, "\0", "\0"); } else { - rc = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "%s/%s agent", - instance_config.remote.path, probackup); + rc = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "%s %s/%s agent", + libenv, instance_config.remote.path, probackup); securec_check_ss_c(rc, "\0", "\0"); } #endif diff --git a/src/bin/pg_probackup/remote.h b/src/bin/pg_probackup/remote.h index dbc250755..81c2b1114 100644 --- a/src/bin/pg_probackup/remote.h +++ b/src/bin/pg_probackup/remote.h @@ -16,6 +16,7 @@ typedef struct RemoteConfig char* host; char* port; char* path; + char* libpath; char* user; char *ssh_config; char *ssh_options;