1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-11-24 08:52:38 +02:00

implement help for probackup commands

This commit is contained in:
Anastasia 2017-05-05 13:14:46 +03:00
parent a6be0c35f4
commit 135f86e13d
6 changed files with 263 additions and 127 deletions

View File

@ -6,6 +6,7 @@ OBJS = backup.o \
delete.o \
dir.o \
fetch.o \
help.o \
init.o \
parray.o \
pg_probackup.o \

238
help.c Normal file
View File

@ -0,0 +1,238 @@
/*-------------------------------------------------------------------------
*
* help.c
*
* Portions Copyright (c) 2017-2017, Postgres Professional
*
*-------------------------------------------------------------------------
*/
#include "pg_probackup.h"
static void help_init(void);
static void help_backup(void);
static void help_restore(void);
static void help_validate(void);
static void help_show(void);
static void help_delete(void);
static void help_set_config(void);
static void help_show_config(void);
void
help_command(char *command)
{
if (strcmp(command, "init") == 0)
help_init();
else if (strcmp(command, "backup") == 0)
help_backup();
else if (strcmp(command, "restore") == 0)
help_restore();
else if (strcmp(command, "validate") == 0)
help_validate();
else if (strcmp(command, "show") == 0)
help_show();
else if (strcmp(command, "delete") == 0)
help_delete();
else if (strcmp(command, "set-config") == 0)
help_set_config();
else if (strcmp(command, "show-config") == 0)
help_show_config();
else if (strcmp(command, "--help") == 0
|| strcmp(command, "help") == 0
|| strcmp(command, "-?") == 0
|| strcmp(command, "--version") == 0
|| strcmp(command, "version") == 0
|| strcmp(command, "-V") == 0)
printf(_("No help page for \"%s\" command. Try pg_probackup help\n"), command);
else
printf(_("Unknown command. Try pg_probackup help\n"));
exit(0);
}
void
help_pg_probackup(void)
{
printf(_("\n%s - utility to manage backup/recovery of PostgreSQL database.\n\n"), PROGRAM_NAME);
printf(_(" %s help [COMMAND]\n"), PROGRAM_NAME);
printf(_("\n %s version\n"), PROGRAM_NAME);
printf(_("\n %s init -B backup-path -D pgdata-dir\n"), PROGRAM_NAME);
printf(_("\n %s set-config -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [-d dbname] [-h host] [-p port] [-U username]\n"));
printf(_(" [--retention-redundancy=retention-redundancy]]\n"));
printf(_(" [--retention-window=retention-window]\n"));
printf(_("\n %s show-config -B backup-dir\n"), PROGRAM_NAME);
printf(_("\n %s backup -B backup-path -b backup-mode\n"), PROGRAM_NAME);
printf(_(" [-D pgdata-dir] [-C] [--stream [-S slot-name]] [--backup-pg-log]\n"));
printf(_(" [-j num-threads] [--archive-timeout=archive-timeout]\n"));
printf(_(" [--progress] [-q] [-v] [--delete-expired]\n"));
printf(_(" [-d dbname] [-h host] [-p port] [-U username]\n"));
printf(_("\n %s restore -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [-D pgdata-dir] [-i backup-id] [--progress] [-q] [-v]\n"));
printf(_(" [--time=time|--xid=xid [--inclusive=boolean]]\n"));
printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n"));
printf(_("\n %s validate -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [-D pgdata-dir] [-i backup-id] [--progress] [-q] [-v]\n"));
printf(_(" [--time=time|--xid=xid [--inclusive=boolean]]\n"));
printf(_(" [--timeline=timeline]\n"));
printf(_("\n %s show -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [-i backup-id]\n"));
printf(_("\n %s delete -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [--wal] [-i backup-id | --expired]\n"));
if ((PROGRAM_URL || PROGRAM_EMAIL))
{
printf("\n");
if (PROGRAM_URL)
printf("Read the website for details. <%s>\n", PROGRAM_URL);
if (PROGRAM_EMAIL)
printf("Report bugs to <%s>.\n", PROGRAM_EMAIL);
}
exit(0);
}
static void
help_init(void)
{
printf(_("%s init -B backup-path -D pgdata-dir\n\n"), PROGRAM_NAME);
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
printf(_(" -D, --pgdata=pgdata-dir location of the database storage area\n"));
}
static void
help_backup(void)
{
printf(_("%s backup -B backup-path -b backup-mode\n"), PROGRAM_NAME);
printf(_(" [-D pgdata-dir] [-C] [--stream [-S slot-name]] [--backup-pg-log]\n"));
printf(_(" [-j num-threads] [--archive-timeout=archive-timeout]\n"));
printf(_(" [--progress] [-q] [-v] [--delete-expired]\n"));
printf(_(" [-d dbname] [-h host] [-p port] [-U username]\n\n"));
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
printf(_(" -b, --backup-mode=backup-mode backup mode=FULL|PAGE|PTRACK\n"));
printf(_(" -D, --pgdata=pgdata-dir location of the database storage area\n"));
printf(_(" -C, --smooth-checkpoint do smooth checkpoint before backup\n"));
printf(_(" --stream stream the transaction log and include it in the backup\n"));
printf(_(" --archive-timeout wait timeout for WAL segment archiving\n"));
printf(_(" -S, --slot=SLOTNAME replication slot to use\n"));
printf(_(" --backup-pg-log backup of pg_log directory\n"));
printf(_(" -j, --threads=NUM number of parallel threads\n"));
printf(_(" --progress show progress\n"));
printf(_(" -q, --quiet don't write any messages\n"));
printf(_(" -v, --verbose verbose mode\n"));
printf(_(" --delete-expired delete backups expired according to current\n"));
printf(_(" retention policy after successful backup completion\n"));
printf(_("\n Connection options:\n"));
printf(_(" -d, --dbname=DBNAME database to connect\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port\n"));
printf(_(" -U, --username=USERNAME user name to connect as\n"));
}
static void
help_restore(void)
{
printf(_("%s restore -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [-D pgdata-dir] [-i backup-id] [--progress] [-q] [-v]\n"));
printf(_(" [--time=time|--xid=xid [--inclusive=boolean]]\n"));
printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n\n"));
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
printf(_(" -D, --pgdata=pgdata-dir location of the database storage area\n"));
printf(_(" -i, --backup-id=backup-id backup to restore\n"));
printf(_(" --progress show progress\n"));
printf(_(" -q, --quiet don't write any messages\n"));
printf(_(" -v, --verbose verbose mode\n"));
printf(_(" --time=time time stamp up to which recovery will proceed\n"));
printf(_(" --xid=xid transaction ID up to which recovery will proceed\n"));
printf(_(" --inclusive=boolean whether we stop just after the recovery target\n"));
printf(_(" --timeline=timeline recovering into a particular timeline\n"));
printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"));
printf(_(" relocate the tablespace from directory OLDDIR to NEWDIR\n"));
}
static void
help_validate(void)
{
printf(_("%s validate -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [-D pgdata-dir] [-i backup-id] [--progress] [-q] [-v]\n"));
printf(_(" [--time=time|--xid=xid [--inclusive=boolean]]\n"));
printf(_(" [--timeline=timeline]\n\n"));
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
printf(_(" -D, --pgdata=pgdata-dir location of the database storage area\n"));
printf(_(" -i, --backup-id=backup-id backup to validate\n"));
printf(_(" --progress show progress\n"));
printf(_(" -q, --quiet don't write any messages\n"));
printf(_(" -v, --verbose verbose mode\n"));
printf(_(" --time=time time stamp up to which recovery will proceed\n"));
printf(_(" --xid=xid transaction ID up to which recovery will proceed\n"));
printf(_(" --inclusive=boolean whether we stop just after the recovery target\n"));
printf(_(" --timeline=timeline recovering into a particular timeline\n"));
}
static void
help_show(void)
{
printf(_("%s show -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [-i backup-id]\n\n"));
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
printf(_(" -i, --backup-id=backup-id show info about specific backups\n"));
}
static void
help_delete(void)
{
printf(_("%s delete -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [--wal] [-i backup-id | --expired]\n\n"));
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
printf(_(" --wal remove unnecessary wal files\n"));
printf(_(" -i, --backup-id=backup-id backup to delete\n"));
printf(_(" --expired delete backups expired according to current\n"));
printf(_(" retention policy\n"));
}
static void
help_set_config(void)
{
printf(_("%s set-config -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [-d dbname] [-h host] [-p port] [-U username]\n"));
printf(_(" [--retention-redundancy=retention-redundancy]]\n"));
printf(_(" [--retention-window=retention-window]\n\n"));
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
printf(_("\n Connection options:\n"));
printf(_(" -d, --dbname=DBNAME database to connect\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port\n"));
printf(_(" -U, --username=USERNAME user name to connect as\n"));
printf(_("\n Retention options:\n"));
printf(_(" --retention-redundancy=retention-redundancy\n"));
printf(_(" number of full backups to keep\n"));
printf(_(" --retention-window=retention-window\n"));
printf(_(" number of days of recoverability\n"));
}
static void
help_show_config(void)
{
printf(_("%s show-config -B backup-dir\n\n"), PROGRAM_NAME);
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
}

View File

@ -29,6 +29,8 @@ char arclog_path[MAXPGPATH];
pgBackup current;
ProbackupSubcmd backup_subcmd;
bool help = false;
char *backup_id_string_param = NULL;
bool backup_logs = false;
@ -59,6 +61,7 @@ static void opt_backup_mode(pgut_option *opt, const char *arg);
static pgut_option options[] =
{
/* directory options */
{ 'b', 1, "help", &help, SOURCE_CMDLINE },
{ 's', 'D', "pgdata", &pgdata, SOURCE_CMDLINE },
{ 's', 'B', "backup-path", &backup_path, SOURCE_CMDLINE },
/* common options */
@ -141,23 +144,35 @@ main(int argc, char *argv[])
|| strcmp(argv[1], "help") == 0
|| strcmp(argv[1], "-?") == 0)
{
help(true);
exit(0);
if (argc > 2)
help_command(argv[2]);
else
help_pg_probackup();
}
else if (strcmp(argv[1], "--version") == 0
|| strcmp(argv[1], "version") == 0
|| strcmp(argv[1], "-V") == 0)
{
fprintf(stderr, "%s %s\n", PROGRAM_NAME, PROGRAM_VERSION);
exit(0);
if (argc == 2)
{
fprintf(stderr, "%s %s\n", PROGRAM_NAME, PROGRAM_VERSION);
exit(0);
}
else if (strcmp(argv[2], "--help") == 0)
help_command(argv[1]);
else
elog(ERROR, "Invalid arguments for \"%s\" subcommand", argv[1]);
}
else
elog(ERROR, "Invalid subcommand");
elog(ERROR, "Unknown subcommand");
}
/* Parse command line arguments */
pgut_getopt(argc, argv, options);
if (help)
help_command(argv[2]);
if (backup_path == NULL)
{
/* Try to read BACKUP_PATH from environment variable */
@ -263,92 +278,6 @@ main(int argc, char *argv[])
return 0;
}
/* TODO Update help in accordance with new options */
void
pgut_help(bool details)
{
printf(_("\n%s - utility to manage backup/recovery of PostgreSQL database.\n\n"), PROGRAM_NAME);
printf(_(" %s help\n"), PROGRAM_NAME);
printf(_("\n %s version\n"), PROGRAM_NAME);
printf(_("\n %s init -B backup-path -D pgdata-dir\n"), PROGRAM_NAME);
printf(_("\n %s set-config -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [-d dbname] [-h host] [-p port] [-U username]\n"));
printf(_(" [--retention-redundancy=retention-redundancy]]\n"));
printf(_(" [--retention-window=retention-window]\n"));
printf(_("\n %s show-config -B backup-dir\n"), PROGRAM_NAME);
printf(_("\n %s backup -B backup-path -b backup-mode\n"), PROGRAM_NAME);
printf(_(" [-D pgdata-dir] [-C] [--stream [-S slot-name]] [--backup-pg-log]\n"));
printf(_(" [-j num-threads] [--archive-timeout=archive-timeout]\n"));
printf(_(" [--progress] [-q] [-v] [--delete-expired]\n"));
printf(_(" [-d dbname] [-h host] [-p port] [-U username]\n"));
printf(_("\n %s restore -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [-D pgdata-dir] [-i backup-id]\n"));
printf(_(" [--time=time|--xid=xid [--inclusive=boolean]]\n"));
printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n"));
printf(_("\n %s validate -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [-D pgdata-dir] [-i backup-id]\n"));
printf(_(" [--time=time|--xid=xid [--inclusive=boolean]]\n"));
printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n"));
printf(_("\n %s show -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [-i backup-id]\n"));
printf(_("\n %s delete -B backup-dir\n"), PROGRAM_NAME);
printf(_(" [--wal] [-i backup-id | --expired] [--force]\n"));
// printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
// printf(_(" -D, --pgdata=pgdata-dir location of the database storage area\n"));
// printf(_(" -b, --backup-mode=backup-mode backup mode=FULL|PAGE|PTRACK\n"));
// printf(" Connection options:\n");
// printf(" -d, --dbname=DBNAME database to connect\n");
// printf(" -h, --host=HOSTNAME database server host or socket directory\n");
// printf(" -p, --port=PORT database server port\n");
// printf(" -U, --username=USERNAME user name to connect as\n");
// printf(" -w, --no-password never prompt for password\n");
// printf(" -W, --password force password prompt\n");
// printf(" Retention options:\n");
// printf(_(" --retention-redundancy=n-full-backups specifies how many full backups purge command should keep\n"));
// printf(_(" --retention-window=n-days specifies the number of days of recoverability\n"));
//
//
// printf(_("\nOptional p:\n"));
// printf(_(" -B, --backup-path=PATH location of the backup storage area\n"));
// printf(_(" -D, --pgdata=PATH location of the database storage area\n"));
// /*printf(_(" -c, --check show what would have been done\n"));*/
// printf(_("\nBackup options:\n"));
// printf(_(" -b, --backup-mode=MODE backup mode (full, page, ptrack)\n"));
// printf(_(" -C, --smooth-checkpoint do smooth checkpoint before backup\n"));
// printf(_(" --stream stream the transaction log and include it in the backup\n"));
// printf(_(" --archive-timeout wait timeout for WAL segment archiving\n"));
// printf(_(" -S, --slot=SLOTNAME replication slot to use\n"));
// printf(_(" --backup-pg-log backup of pg_log directory\n"));
// printf(_(" -j, --threads=NUM number of parallel threads\n"));
// printf(_(" --progress show progress\n"));
// printf(_("\nRestore options:\n"));
// printf(_(" --time time stamp up to which recovery will proceed\n"));
// printf(_(" --xid transaction ID up to which recovery will proceed\n"));
// printf(_(" --inclusive whether we stop just after the recovery target\n"));
// printf(_(" --timeline recovering into a particular timeline\n"));
// printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"));
// printf(_(" relocate the tablespace in directory OLDDIR to NEWDIR\n"));
// printf(_(" -j, --threads=NUM number of parallel threads\n"));
// printf(_(" --progress show progress\n"));
// printf(_("\nDelete options:\n"));
// printf(_(" --wal remove unnecessary wal files\n"));
// printf(_("\nRetention options:\n"));
// printf(_(" --redundancy specifies how many full backups purge command should keep\n"));
// printf(_(" --window specifies the number of days of recoverability\n"));
}
static void
opt_backup_mode(pgut_option *opt, const char *arg)
{

View File

@ -296,6 +296,10 @@ extern char *slurpFile(const char *datadir,
size_t *filesize,
bool safe);
/* in help.c */
extern void help_pg_probackup(void);
extern void help_command(char *command);
/* in validate.c */
extern void pgBackupValidate(pgBackup* backup);

View File

@ -1286,41 +1286,6 @@ exit_or_abort(int exitcode)
}
}
void
help(bool details)
{
pgut_help(details);
// if (details)
// {
// printf("\nConnection options:\n");
// printf(" -d, --dbname=DBNAME database to connect\n");
// printf(" -h, --host=HOSTNAME database server host or socket directory\n");
// printf(" -p, --port=PORT database server port\n");
// printf(" -U, --username=USERNAME user name to connect as\n");
// printf(" -w, --no-password never prompt for password\n");
// printf(" -W, --password force password prompt\n");
// }
//
// printf("\nGeneric options:\n");
// if (details)
// {
// printf(" -q, --quiet don't write any messages\n");
// printf(" -v, --verbose verbose mode\n");
// }
// printf(" --help show this help, then exit\n");
// printf(" --version output version information and exit\n");
if (details && (PROGRAM_URL || PROGRAM_EMAIL))
{
printf("\n");
if (PROGRAM_URL)
printf("Read the website for details. <%s>\n", PROGRAM_URL);
if (PROGRAM_EMAIL)
printf("Report bugs to <%s>.\n", PROGRAM_EMAIL);
}
}
/*
* Returns the current user name.
*/

View File

@ -89,7 +89,6 @@ extern bool prompt_password;
extern bool interrupted;
extern void help(bool details);
extern int pgut_getopt(int argc, char **argv, pgut_option options[]);
extern void pgut_readopt(const char *path, pgut_option options[], int elevel);
extern void pgut_getopt_env(pgut_option options[]);