Skip to content

Commit 0985222

Browse files
committed
Show command line for BACKUP, RESTORE, VALIDATE, DELETE
1 parent c5f5ddc commit 0985222

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/pg_probackup.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static pgut_option options[] =
176176
int
177177
main(int argc, char *argv[])
178178
{
179-
char *command;
179+
char *command = NULL;
180180
char path[MAXPGPATH];
181181
/* Check if backup_path is directory. */
182182
struct stat stat_buf;
@@ -253,22 +253,29 @@ main(int argc, char *argv[])
253253
* Make command string before getopt_long() will call. It permutes the
254254
* content of argv.
255255
*/
256-
if (backup_subcmd == BACKUP)
256+
if (backup_subcmd == BACKUP ||
257+
backup_subcmd == RESTORE ||
258+
backup_subcmd == VALIDATE ||
259+
backup_subcmd == DELETE)
257260
{
258261
int i,
259-
len = 0;
262+
len = 0,
263+
allocated = 0;
260264

261-
command = (char *) palloc(sizeof(char) * MAXPGPATH);
262-
command[0] = '\0';
265+
allocated = sizeof(char) * MAXPGPATH;
266+
command = (char *) palloc(allocated);
263267

264268
for (i = 0; i < argc; i++)
265269
{
266270
int arglen = strlen(argv[i]);
267271

268-
if (arglen + len > MAXPGPATH)
269-
break;
272+
if (arglen + len > allocated)
273+
{
274+
allocated *= 2;
275+
command = repalloc(command, allocated);
276+
}
270277

271-
strncpy((command +len), argv[i], arglen);
278+
strncpy(command + len, argv[i], arglen);
272279
len += arglen;
273280
command[len++] = ' ';
274281
}
@@ -303,6 +310,18 @@ main(int argc, char *argv[])
303310
if (rc != -1 && !S_ISDIR(stat_buf.st_mode))
304311
elog(ERROR, "-B, --backup-path must be a path to directory");
305312

313+
/* Initialize logger */
314+
init_logger(backup_path);
315+
316+
/* command was initialized for a few commands */
317+
if (command)
318+
{
319+
elog_file(INFO, "command: %s", command);
320+
321+
pfree(command);
322+
command = NULL;
323+
}
324+
306325
/* Option --instance is required for all commands except init and show */
307326
if (backup_subcmd != INIT && backup_subcmd != SHOW && backup_subcmd != VALIDATE)
308327
{
@@ -353,9 +372,6 @@ main(int argc, char *argv[])
353372
if (pgdata != NULL && !is_absolute_path(pgdata))
354373
elog(ERROR, "-D, --pgdata must be an absolute path");
355374

356-
/* Initialize logger */
357-
init_logger(backup_path);
358-
359375
/* Sanity check of --backup-id option */
360376
if (backup_id_string_param != NULL)
361377
{
@@ -422,7 +438,6 @@ main(int argc, char *argv[])
422438
elog(INFO, "Backup start, pg_probackup version: %s, backup ID: %s, backup mode: %s, instance: %s, stream: %s, remote: %s",
423439
PROGRAM_VERSION, base36enc(start_time), backup_mode, instance_name,
424440
current.stream ? "true" : "false", is_remote_backup ? "true" : "false");
425-
elog_file(INFO, "command: %s", command);
426441

427442
return do_backup(start_time);
428443
}

0 commit comments

Comments
 (0)