@@ -176,7 +176,7 @@ static pgut_option options[] =
176
176
int
177
177
main (int argc , char * argv [])
178
178
{
179
- char * command ;
179
+ char * command = NULL ;
180
180
char path [MAXPGPATH ];
181
181
/* Check if backup_path is directory. */
182
182
struct stat stat_buf ;
@@ -253,22 +253,29 @@ main(int argc, char *argv[])
253
253
* Make command string before getopt_long() will call. It permutes the
254
254
* content of argv.
255
255
*/
256
- if (backup_subcmd == BACKUP )
256
+ if (backup_subcmd == BACKUP ||
257
+ backup_subcmd == RESTORE ||
258
+ backup_subcmd == VALIDATE ||
259
+ backup_subcmd == DELETE )
257
260
{
258
261
int i ,
259
- len = 0 ;
262
+ len = 0 ,
263
+ allocated = 0 ;
260
264
261
- command = ( char * ) palloc ( sizeof (char ) * MAXPGPATH ) ;
262
- command [ 0 ] = '\0' ;
265
+ allocated = sizeof (char ) * MAXPGPATH ;
266
+ command = ( char * ) palloc ( allocated ) ;
263
267
264
268
for (i = 0 ; i < argc ; i ++ )
265
269
{
266
270
int arglen = strlen (argv [i ]);
267
271
268
- if (arglen + len > MAXPGPATH )
269
- break ;
272
+ if (arglen + len > allocated )
273
+ {
274
+ allocated *= 2 ;
275
+ command = repalloc (command , allocated );
276
+ }
270
277
271
- strncpy (( command + len ) , argv [i ], arglen );
278
+ strncpy (command + len , argv [i ], arglen );
272
279
len += arglen ;
273
280
command [len ++ ] = ' ' ;
274
281
}
@@ -303,6 +310,18 @@ main(int argc, char *argv[])
303
310
if (rc != -1 && !S_ISDIR (stat_buf .st_mode ))
304
311
elog (ERROR , "-B, --backup-path must be a path to directory" );
305
312
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
+
306
325
/* Option --instance is required for all commands except init and show */
307
326
if (backup_subcmd != INIT && backup_subcmd != SHOW && backup_subcmd != VALIDATE )
308
327
{
@@ -353,9 +372,6 @@ main(int argc, char *argv[])
353
372
if (pgdata != NULL && !is_absolute_path (pgdata ))
354
373
elog (ERROR , "-D, --pgdata must be an absolute path" );
355
374
356
- /* Initialize logger */
357
- init_logger (backup_path );
358
-
359
375
/* Sanity check of --backup-id option */
360
376
if (backup_id_string_param != NULL )
361
377
{
@@ -422,7 +438,6 @@ main(int argc, char *argv[])
422
438
elog (INFO , "Backup start, pg_probackup version: %s, backup ID: %s, backup mode: %s, instance: %s, stream: %s, remote: %s" ,
423
439
PROGRAM_VERSION , base36enc (start_time ), backup_mode , instance_name ,
424
440
current .stream ? "true" : "false" , is_remote_backup ? "true" : "false" );
425
- elog_file (INFO , "command: %s" , command );
426
441
427
442
return do_backup (start_time );
428
443
}
0 commit comments