Skip to content

Commit 00be188

Browse files
committed
Merge commit 'refs/pull/291/head' of https://github.com/postgrespro/pg_probackup
2 parents 964d8db + 3f09845 commit 00be188

File tree

17 files changed

+485
-205
lines changed

17 files changed

+485
-205
lines changed

doc/pgprobackup.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3586,7 +3586,7 @@ pg_probackup show-config -B <replaceable>backup_dir</replaceable> --instance <re
35863586
<title>show</title>
35873587
<programlisting>
35883588
pg_probackup show -B <replaceable>backup_dir</replaceable>
3589-
[--help] [--instance <replaceable>instance_name</replaceable> [-i <replaceable>backup_id</replaceable> | --archive]] [--format=plain|json]
3589+
[--help] [--instance <replaceable>instance_name</replaceable> [-i <replaceable>backup_id</replaceable> | --archive]] [--format=plain|json] [--no-color]
35903590
</programlisting>
35913591
<para>
35923592
Shows the contents of the backup catalog. If
@@ -3601,6 +3601,8 @@ pg_probackup show -B <replaceable>backup_dir</replaceable>
36013601
plain text. You can specify the
36023602
<literal>--format=json</literal> option to get the result
36033603
in the <acronym>JSON</acronym> format.
3604+
If <literal>--no-color</literal> flag is used,
3605+
then the output is not colored.
36043606
</para>
36053607
<para>
36063608
For details on usage, see the sections
@@ -4628,6 +4630,16 @@ pg_probackup archive-get -B <replaceable>backup_dir</replaceable> --instance <re
46284630
</para>
46294631
<para>
46304632
<variablelist>
4633+
4634+
<varlistentry>
4635+
<term><option>--no-color</option></term>
4636+
<listitem>
4637+
<para>
4638+
Disable the coloring for console log messages of <literal>warning</literal> and <literal>error</literal> levels.
4639+
</para>
4640+
</listitem>
4641+
</varlistentry>
4642+
46314643
<varlistentry>
46324644
<term><option>--log-level-console=<replaceable>log_level</replaceable></option></term>
46334645
<listitem>

src/backup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ do_backup(time_t start_time, pgSetBackupParams *set_backup_params,
757757

758758
elog(INFO, "Backup start, pg_probackup version: %s, instance: %s, backup ID: %s, backup mode: %s, "
759759
"wal mode: %s, remote: %s, compress-algorithm: %s, compress-level: %i",
760-
PROGRAM_VERSION, instance_name, base36enc(start_time), pgBackupGetBackupMode(&current),
760+
PROGRAM_VERSION, instance_name, base36enc(start_time), pgBackupGetBackupMode(&current, false),
761761
current.stream ? "STREAM" : "ARCHIVE", IsSshProtocol() ? "true" : "false",
762762
deparse_compress_alg(current.compress_alg), current.compress_level);
763763

src/catalog.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,22 @@ lock_backup_read_only(pgBackup *backup)
655655
* Get backup_mode in string representation.
656656
*/
657657
const char *
658-
pgBackupGetBackupMode(pgBackup *backup)
658+
pgBackupGetBackupMode(pgBackup *backup, bool show_color)
659659
{
660-
return backupModes[backup->backup_mode];
660+
if (show_color)
661+
{
662+
/* color the Backup mode */
663+
char *mode = pgut_malloc(24); /* leaking memory here */
664+
665+
if (backup->backup_mode == BACKUP_MODE_FULL)
666+
snprintf(mode, 24, "%s%s%s", TC_GREEN_BOLD, backupModes[backup->backup_mode], TC_RESET);
667+
else
668+
snprintf(mode, 24, "%s%s%s", TC_BLUE_BOLD, backupModes[backup->backup_mode], TC_RESET);
669+
670+
return mode;
671+
}
672+
else
673+
return backupModes[backup->backup_mode];
661674
}
662675

663676
static bool
@@ -2008,7 +2021,7 @@ pgBackupWriteControl(FILE *out, pgBackup *backup, bool utc)
20082021
char timestamp[100];
20092022

20102023
fio_fprintf(out, "#Configuration\n");
2011-
fio_fprintf(out, "backup-mode = %s\n", pgBackupGetBackupMode(backup));
2024+
fio_fprintf(out, "backup-mode = %s\n", pgBackupGetBackupMode(backup, false));
20122025
fio_fprintf(out, "stream = %s\n", backup->stream ? "true" : "false");
20132026
fio_fprintf(out, "compress-alg = %s\n",
20142027
deparse_compress_alg(backup->compress_alg));

src/delete.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
405405
/* TODO: add ancestor(chain full backup) ID */
406406
elog(INFO, "Backup %s, mode: %s, status: %s. Redundancy: %i/%i, Time Window: %ud/%ud. %s",
407407
base36enc(backup->start_time),
408-
pgBackupGetBackupMode(backup),
408+
pgBackupGetBackupMode(backup, false),
409409
status2str(backup->status),
410410
cur_full_backup_num,
411411
instance_config.retention_redundancy,

src/help.c

Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
*-------------------------------------------------------------------------
88
*/
99

10+
#include <assert.h>
1011
#include "pg_probackup.h"
1112

13+
static void help_nocmd(void);
1214
static void help_init(void);
1315
static void help_backup(void);
1416
static void help_restore(void);
@@ -24,50 +26,52 @@ static void help_del_instance(void);
2426
static void help_archive_push(void);
2527
static void help_archive_get(void);
2628
static void help_checkdb(void);
29+
static void help_help(void);
2730

2831
void
29-
help_command(char *command)
32+
help_print_version(void)
3033
{
31-
if (strcmp(command, "init") == 0)
32-
help_init();
33-
else if (strcmp(command, "backup") == 0)
34-
help_backup();
35-
else if (strcmp(command, "restore") == 0)
36-
help_restore();
37-
else if (strcmp(command, "validate") == 0)
38-
help_validate();
39-
else if (strcmp(command, "show") == 0)
40-
help_show();
41-
else if (strcmp(command, "delete") == 0)
42-
help_delete();
43-
else if (strcmp(command, "merge") == 0)
44-
help_merge();
45-
else if (strcmp(command, "set-backup") == 0)
46-
help_set_backup();
47-
else if (strcmp(command, "set-config") == 0)
48-
help_set_config();
49-
else if (strcmp(command, "show-config") == 0)
50-
help_show_config();
51-
else if (strcmp(command, "add-instance") == 0)
52-
help_add_instance();
53-
else if (strcmp(command, "del-instance") == 0)
54-
help_del_instance();
55-
else if (strcmp(command, "archive-push") == 0)
56-
help_archive_push();
57-
else if (strcmp(command, "archive-get") == 0)
58-
help_archive_get();
59-
else if (strcmp(command, "checkdb") == 0)
60-
help_checkdb();
61-
else if (strcmp(command, "--help") == 0
62-
|| strcmp(command, "help") == 0
63-
|| strcmp(command, "-?") == 0
64-
|| strcmp(command, "--version") == 0
65-
|| strcmp(command, "version") == 0
66-
|| strcmp(command, "-V") == 0)
67-
printf(_("No help page for \"%s\" command. Try pg_probackup help\n"), command);
68-
else
69-
printf(_("Unknown command \"%s\". Try pg_probackup help\n"), command);
70-
exit(0);
34+
#ifdef PGPRO_VERSION
35+
fprintf(stdout, "%s %s (Postgres Pro %s %s)\n",
36+
PROGRAM_NAME, PROGRAM_VERSION,
37+
PGPRO_VERSION, PGPRO_EDITION);
38+
#else
39+
fprintf(stdout, "%s %s (PostgreSQL %s)\n",
40+
PROGRAM_NAME, PROGRAM_VERSION, PG_VERSION);
41+
#endif
42+
}
43+
44+
void
45+
help_command(ProbackupSubcmd const subcmd)
46+
{
47+
typedef void (* help_function_ptr)(void);
48+
/* Order is important, keep it in sync with utils/configuration.h:enum ProbackupSubcmd declaration */
49+
static help_function_ptr const help_functions[] =
50+
{
51+
&help_nocmd,
52+
&help_init,
53+
&help_add_instance,
54+
&help_del_instance,
55+
&help_archive_push,
56+
&help_archive_get,
57+
&help_backup,
58+
&help_restore,
59+
&help_validate,
60+
&help_delete,
61+
&help_merge,
62+
&help_show,
63+
&help_set_config,
64+
&help_set_backup,
65+
&help_show_config,
66+
&help_checkdb,
67+
&help_nocmd, // SSH_CMD
68+
&help_nocmd, // AGENT_CMD
69+
&help_help,
70+
&help_help, // VERSION_CMD
71+
};
72+
73+
Assert((int)subcmd < sizeof(help_functions) / sizeof(help_functions[0]));
74+
help_functions[(int)subcmd]();
7175
}
7276

7377
void
@@ -127,7 +131,7 @@ help_pg_probackup(void)
127131
printf(_(" [--error-log-filename=error-log-filename]\n"));
128132
printf(_(" [--log-directory=log-directory]\n"));
129133
printf(_(" [--log-rotation-size=log-rotation-size]\n"));
130-
printf(_(" [--log-rotation-age=log-rotation-age]\n"));
134+
printf(_(" [--log-rotation-age=log-rotation-age] [--no-color]\n"));
131135
printf(_(" [--delete-expired] [--delete-wal] [--merge-expired]\n"));
132136
printf(_(" [--retention-redundancy=retention-redundancy]\n"));
133137
printf(_(" [--retention-window=retention-window]\n"));
@@ -188,7 +192,7 @@ help_pg_probackup(void)
188192
printf(_("\n %s show -B backup-path\n"), PROGRAM_NAME);
189193
printf(_(" [--instance=instance_name [-i backup-id]]\n"));
190194
printf(_(" [--format=format] [--archive]\n"));
191-
printf(_(" [--help]\n"));
195+
printf(_(" [--no-color] [--help]\n"));
192196

193197
printf(_("\n %s delete -B backup-path --instance=instance_name\n"), PROGRAM_NAME);
194198
printf(_(" [-j num-threads] [--progress]\n"));
@@ -247,7 +251,12 @@ help_pg_probackup(void)
247251
if (PROGRAM_EMAIL)
248252
printf("Report bugs to <%s>.\n", PROGRAM_EMAIL);
249253
}
250-
exit(0);
254+
}
255+
256+
static void
257+
help_nocmd(void)
258+
{
259+
printf(_("Unknown command. Try pg_probackup help\n"));
251260
}
252261

253262
static void
@@ -273,7 +282,7 @@ help_backup(void)
273282
printf(_(" [--error-log-filename=error-log-filename]\n"));
274283
printf(_(" [--log-directory=log-directory]\n"));
275284
printf(_(" [--log-rotation-size=log-rotation-size]\n"));
276-
printf(_(" [--log-rotation-age=log-rotation-age]\n"));
285+
printf(_(" [--log-rotation-age=log-rotation-age] [--no-color]\n"));
277286
printf(_(" [--delete-expired] [--delete-wal] [--merge-expired]\n"));
278287
printf(_(" [--retention-redundancy=retention-redundancy]\n"));
279288
printf(_(" [--retention-window=retention-window]\n"));
@@ -329,6 +338,7 @@ help_backup(void)
329338
printf(_(" --log-rotation-age=log-rotation-age\n"));
330339
printf(_(" rotate logfile if its age exceeds this value; 0 disables; (default: 0)\n"));
331340
printf(_(" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n"));
341+
printf(_(" --no-color disable the coloring of error and warning console messages\n"));
332342

333343
printf(_("\n Retention options:\n"));
334344
printf(_(" --delete-expired delete backups expired according to current\n"));
@@ -489,6 +499,7 @@ help_restore(void)
489499
printf(_(" --log-rotation-age=log-rotation-age\n"));
490500
printf(_(" rotate logfile if its age exceeds this value; 0 disables; (default: 0)\n"));
491501
printf(_(" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n"));
502+
printf(_(" --no-color disable the coloring of error and warning console messages\n"));
492503

493504
printf(_("\n Remote options:\n"));
494505
printf(_(" --remote-proto=protocol remote protocol to use\n"));
@@ -554,7 +565,8 @@ help_validate(void)
554565
printf(_(" available units: 'kB', 'MB', 'GB', 'TB' (default: kB)\n"));
555566
printf(_(" --log-rotation-age=log-rotation-age\n"));
556567
printf(_(" rotate logfile if its age exceeds this value; 0 disables; (default: 0)\n"));
557-
printf(_(" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n\n"));
568+
printf(_(" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n"));
569+
printf(_(" --no-color disable the coloring of error and warning console messages\n\n"));
558570
}
559571

560572
static void
@@ -599,6 +611,7 @@ help_checkdb(void)
599611
printf(_(" --log-rotation-age=log-rotation-age\n"));
600612
printf(_(" rotate logfile if its age exceeds this value; 0 disables; (default: 0)\n"));
601613
printf(_(" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n"));
614+
printf(_(" --no-color disable the coloring of error and warning console messages\n"));
602615

603616
printf(_("\n Connection options:\n"));
604617
printf(_(" -U, --pguser=USERNAME user name to connect as (default: current local user)\n"));
@@ -620,7 +633,8 @@ help_show(void)
620633
printf(_(" --instance=instance_name show info about specific instance\n"));
621634
printf(_(" -i, --backup-id=backup-id show info about specific backups\n"));
622635
printf(_(" --archive show WAL archive information\n"));
623-
printf(_(" --format=format show format=PLAIN|JSON\n\n"));
636+
printf(_(" --format=format show format=PLAIN|JSON\n"));
637+
printf(_(" --no-color disable the coloring for plain format\n\n"));
624638
}
625639

626640
static void
@@ -673,7 +687,8 @@ help_delete(void)
673687
printf(_(" available units: 'kB', 'MB', 'GB', 'TB' (default: kB)\n"));
674688
printf(_(" --log-rotation-age=log-rotation-age\n"));
675689
printf(_(" rotate logfile if its age exceeds this value; 0 disables; (default: 0)\n"));
676-
printf(_(" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n\n"));
690+
printf(_(" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n"));
691+
printf(_(" --no-color disable the coloring of error and warning console messages\n\n"));
677692
}
678693

679694
static void
@@ -715,7 +730,8 @@ help_merge(void)
715730
printf(_(" available units: 'kB', 'MB', 'GB', 'TB' (default: kB)\n"));
716731
printf(_(" --log-rotation-age=log-rotation-age\n"));
717732
printf(_(" rotate logfile if its age exceeds this value; 0 disables; (default: 0)\n"));
718-
printf(_(" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n\n"));
733+
printf(_(" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n"));
734+
printf(_(" --no-color disable the coloring of error and warning console messages\n\n"));
719735
}
720736

721737
static void
@@ -964,3 +980,9 @@ help_archive_get(void)
964980
printf(_(" --ssh-options=ssh_options additional ssh options (default: none)\n"));
965981
printf(_(" (example: --ssh-options='-c cipher_spec -F configfile')\n\n"));
966982
}
983+
984+
static void
985+
help_help(void)
986+
{
987+
printf(_("No help page required for \"help\" and \"version\" commands. Just try it!\n"));
988+
}

0 commit comments

Comments
 (0)