From aee90526fcd4b9bf08b982d09ae5aa2d0a601a7e Mon Sep 17 00:00:00 2001 From: yukai_k Date: Mon, 26 Oct 2020 09:24:08 +0800 Subject: [PATCH] =?UTF-8?q?gs=5Fprobackup=E4=BF=AE=E6=94=B9=20:=201.-W|--p?= =?UTF-8?q?assword=E7=9A=84help=E4=BF=A1=E6=81=AF=E4=BF=AE=E6=94=B9=202.?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8D=E5=8F=AF=E5=90=8C=E6=97=B6=E6=8C=87?= =?UTF-8?q?=E5=AE=9A-w=E5=92=8C-W=E7=9A=84=E6=A3=80=E6=9F=A5=203.=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=8C=87=E5=AE=9A--tablespace-mapping=E6=97=B6?= =?UTF-8?q?=E5=BF=85=E9=A1=BB=E8=A6=81=E6=8C=87=E5=AE=9A--external-mapping?= =?UTF-8?q?=E7=9A=84=E6=A3=80=E6=9F=A5=204.=E5=88=A0=E9=99=A4=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=8F=98=E9=87=8Fforce=5Fpassword?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_probackup/dir.cpp | 6 ++++++ src/bin/pg_probackup/help.cpp | 6 +++--- src/bin/pg_probackup/pg_probackup.cpp | 14 ++++++++++++-- src/bin/pg_probackup/pg_probackup.h | 2 ++ src/bin/pg_probackup/pgut.cpp | 25 +++++-------------------- src/bin/pg_probackup/pgut.h | 1 - 6 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/bin/pg_probackup/dir.cpp b/src/bin/pg_probackup/dir.cpp index cf7943bfa..9ca00cf07 100644 --- a/src/bin/pg_probackup/dir.cpp +++ b/src/bin/pg_probackup/dir.cpp @@ -962,6 +962,12 @@ opt_path_map(ConfigOption *opt, const char *arg, TablespaceList *list, else list->head = cell; list->tail = cell; + + if (strncmp(type, "tablespace", strlen(type)) == 0) { + specify_tbsdir = true; + } else if (strncmp(type, "external directory", strlen(type)) == 0) { + specify_extdir = true; + } } /* Parse tablespace mapping */ diff --git a/src/bin/pg_probackup/help.cpp b/src/bin/pg_probackup/help.cpp index 89f9b89c9..a76eba7d2 100644 --- a/src/bin/pg_probackup/help.cpp +++ b/src/bin/pg_probackup/help.cpp @@ -137,7 +137,7 @@ void help_pg_probackup(void) printf(_(" [--compress-algorithm=compress-algorithm]\n")); printf(_(" [--compress-level=compress-level]\n")); printf(_(" [--compress]\n")); - printf(_(" [-d dbname] [-h host] [-p port] [-U username] [-w] [-W]\n")); + printf(_(" [-d dbname] [-h host] [-p port] [-U username] [-w] [-W password]\n")); printf(_(" [--remote-proto=protocol] [--remote-host=destination]\n")); printf(_(" [--remote-path=path] [--remote-user=username]\n")); printf(_(" [--remote-port=port] [--ssh-options=ssh_options]\n")); @@ -410,7 +410,7 @@ static void help_backup(void) printf(_(" [--compress-algorithm=compress-algorithm]\n")); printf(_(" [--compress-level=compress-level]\n")); printf(_(" [--compress]\n")); - printf(_(" [-d dbname] [-h host] [-p port] [-U username] [-w] [-W]\n")); + printf(_(" [-d dbname] [-h host] [-p port] [-U username] [-w] [-W password]\n")); printf(_(" [--remote-proto=protocol] [--remote-host=destination]\n")); printf(_(" [--remote-path=path] [--remote-user=username]\n")); printf(_(" [--remote-port=port] [--ssh-options=ssh_options]\n")); @@ -484,7 +484,7 @@ static void help_backup(void) printf(_(" -h, --pghost=hostname database server host or socket directory(default: 'local socket')\n")); printf(_(" -p, --pgport=port database server port (default: 5432)\n")); printf(_(" -w, --no-password never prompt for password\n")); - printf(_(" -W, --password force password prompt\n")); + printf(_(" -W, --password=password the password of specified database user\n")); printf(_("\n Remote options:\n")); printf(_(" --remote-proto=protocol remote protocol to use\n")); diff --git a/src/bin/pg_probackup/pg_probackup.cpp b/src/bin/pg_probackup/pg_probackup.cpp index 38270da5a..c056810aa 100644 --- a/src/bin/pg_probackup/pg_probackup.cpp +++ b/src/bin/pg_probackup/pg_probackup.cpp @@ -102,6 +102,9 @@ IncrRestoreMode incremental_mode = INCR_NONE; bool skip_block_validation = false; bool skip_external_dirs = false; +bool specify_extdir = false; +bool specify_tbsdir = false; + /* delete options */ bool delete_wal = false; bool delete_expired = false; @@ -235,8 +238,7 @@ setMyLocation(void) /* * Entry point of pg_probackup command. */ -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { char *command = NULL, *command_name; @@ -382,11 +384,19 @@ main(int argc, char *argv[]) optind += 1; /* Parse command line only arguments */ config_get_opt(argc, argv, cmd_options, instance_options); + if (password) { + if (!prompt_password) { + elog(ERROR, "You cannot specify --password and --no-password options together"); + } replace_password(argc, argv, "-W"); replace_password(argc, argv, "--password"); } + if (specify_tbsdir && !specify_extdir) { + elog(ERROR, "If specify --tablespace-mapping option, you must specify --external-mapping option together"); + } + pgut_init(); if (help_opt) diff --git a/src/bin/pg_probackup/pg_probackup.h b/src/bin/pg_probackup/pg_probackup.h index 3a75e40dd..effdd9f38 100644 --- a/src/bin/pg_probackup/pg_probackup.h +++ b/src/bin/pg_probackup/pg_probackup.h @@ -719,6 +719,8 @@ extern bool compress_shortcut; /* other options */ extern char *instance_name; +extern bool specify_extdir; +extern bool specify_tbsdir; /* show options */ extern ShowFormat show_format; diff --git a/src/bin/pg_probackup/pgut.cpp b/src/bin/pg_probackup/pgut.cpp index 950377bcb..b9d1b2da6 100644 --- a/src/bin/pg_probackup/pgut.cpp +++ b/src/bin/pg_probackup/pgut.cpp @@ -24,8 +24,7 @@ #include "logger.h" #include "file.h" -bool prompt_password = true; -bool force_password = false; +bool prompt_password = true; /* Database connections */ static PGcancel *volatile cancel_conn = NULL; @@ -554,21 +553,14 @@ escapeConnectionParameter(const char *src) /* TODO: it is better to use PQconnectdbParams like in psql * It will allow to set application_name for pg_probackup */ -PGconn * -pgut_connect(const char *host, const char *port, - const char *dbname, const char *username) +PGconn* pgut_connect(const char *host, const char *port, + const char *dbname, const char *username) { PGconn *conn; if (interrupted && !in_cleanup) elog(ERROR, "interrupted"); - if (force_password && !prompt_password) - elog(ERROR, "You cannot specify --password and --no-password options together"); - - if (!password && force_password) - prompt_for_password(username); - /* Start the connection. Loop until we have a password if requested by backend. */ for (;;) { @@ -602,9 +594,8 @@ pgut_connect(const char *host, const char *port, } } -PGconn * -pgut_connect_replication(const char *host, const char *port, - const char *dbname, const char *username) +PGconn* pgut_connect_replication(const char *host, const char *port, + const char *dbname, const char *username) { PGconn *tmpconn; int argcount = 7; /* dbname, replication, fallback_app_name, @@ -616,12 +607,6 @@ pgut_connect_replication(const char *host, const char *port, if (interrupted && !in_cleanup) elog(ERROR, "interrupted"); - if (force_password && !prompt_password) - elog(ERROR, "You cannot specify --password and --no-password options together"); - - if (!password && force_password) - prompt_for_password(username); - i = 0; keywords = (const char**)pg_malloc0((argcount + 1) * sizeof(*keywords)); diff --git a/src/bin/pg_probackup/pgut.h b/src/bin/pg_probackup/pgut.h index eddc20d82..838e4e6a4 100644 --- a/src/bin/pg_probackup/pgut.h +++ b/src/bin/pg_probackup/pgut.h @@ -23,7 +23,6 @@ extern void pgut_help(bool details); * pgut framework variables and functions */ extern bool prompt_password; -extern bool force_password; extern bool interrupted; extern bool in_cleanup;