2
2
*
3
3
* configure.c: - manage backup catalog.
4
4
*
5
- * Copyright (c) 2017-2017 , Postgres Professional
5
+ * Copyright (c) 2017-2018 , Postgres Professional
6
6
*
7
7
*-------------------------------------------------------------------------
8
8
*/
9
9
10
10
#include "pg_probackup.h"
11
11
12
+ #include "pqexpbuffer.h"
13
+
14
+ #include "utils/json.h"
15
+
16
+
12
17
static void opt_log_level_console (pgut_option * opt , const char * arg );
13
18
static void opt_log_level_file (pgut_option * opt , const char * arg );
14
19
static void opt_compress_alg (pgut_option * opt , const char * arg );
15
20
21
+ static void show_configure_start (void );
22
+ static void show_configure_end (void );
23
+ static void show_configure (pgBackupConfig * config );
24
+
25
+ static void show_configure_json (pgBackupConfig * config );
26
+
16
27
static pgBackupConfig * cur_config = NULL ;
17
28
29
+ static PQExpBufferData show_buf ;
30
+ static int32 json_level = 0 ;
31
+
18
32
/* Set configure options */
19
33
int
20
34
do_configure (bool show_only )
@@ -68,7 +82,7 @@ do_configure(bool show_only)
68
82
config -> compress_level = compress_level ;
69
83
70
84
if (show_only )
71
- writeBackupCatalogConfig ( stderr , config );
85
+ show_configure ( config );
72
86
else
73
87
writeBackupCatalogConfigFile (config );
74
88
@@ -251,7 +265,6 @@ readBackupCatalogConfigFile(void)
251
265
pgut_readopt (path , options , ERROR );
252
266
253
267
return config ;
254
-
255
268
}
256
269
257
270
static void
@@ -271,3 +284,146 @@ opt_compress_alg(pgut_option *opt, const char *arg)
271
284
{
272
285
cur_config -> compress_alg = parse_compress_alg (arg );
273
286
}
287
+
288
+ /*
289
+ * Initialize configure visualization.
290
+ */
291
+ static void
292
+ show_configure_start (void )
293
+ {
294
+ if (show_format == SHOW_PLAIN )
295
+ return ;
296
+
297
+ /* For now we need buffer only for JSON format */
298
+ json_level = 0 ;
299
+ initPQExpBuffer (& show_buf );
300
+ }
301
+
302
+ /*
303
+ * Finalize configure visualization.
304
+ */
305
+ static void
306
+ show_configure_end (void )
307
+ {
308
+ if (show_format == SHOW_PLAIN )
309
+ return ;
310
+ else
311
+ appendPQExpBufferChar (& show_buf , '\n' );
312
+
313
+ fputs (show_buf .data , stdout );
314
+ termPQExpBuffer (& show_buf );
315
+ }
316
+
317
+ /*
318
+ * Show configure information of pg_probackup.
319
+ */
320
+ static void
321
+ show_configure (pgBackupConfig * config )
322
+ {
323
+ show_configure_start ();
324
+
325
+ if (show_format == SHOW_PLAIN )
326
+ writeBackupCatalogConfig (stdout , config );
327
+ else
328
+ show_configure_json (config );
329
+
330
+ show_configure_end ();
331
+ }
332
+
333
+ /*
334
+ * Json output.
335
+ */
336
+
337
+ static void
338
+ show_configure_json (pgBackupConfig * config )
339
+ {
340
+ PQExpBuffer buf = & show_buf ;
341
+
342
+ json_add (buf , JT_BEGIN_OBJECT , & json_level );
343
+
344
+ json_add_value (buf , "pgdata" , config -> pgdata , json_level , false);
345
+
346
+ json_add_key (buf , "system-identifier" , json_level , true);
347
+ appendPQExpBuffer (buf , UINT64_FORMAT , config -> system_identifier );
348
+
349
+ /* Connection parameters */
350
+ if (config -> pgdatabase )
351
+ json_add_value (buf , "pgdatabase" , config -> pgdatabase , json_level , true);
352
+ if (config -> pghost )
353
+ json_add_value (buf , "pghost" , config -> pghost , json_level , true);
354
+ if (config -> pgport )
355
+ json_add_value (buf , "pgport" , config -> pgport , json_level , true);
356
+ if (config -> pguser )
357
+ json_add_value (buf , "pguser" , config -> pguser , json_level , true);
358
+
359
+ /* Replica parameters */
360
+ if (config -> master_host )
361
+ json_add_value (buf , "master-host" , config -> master_host , json_level ,
362
+ true);
363
+ if (config -> master_port )
364
+ json_add_value (buf , "master-port" , config -> master_port , json_level ,
365
+ true);
366
+ if (config -> master_db )
367
+ json_add_value (buf , "master-db" , config -> master_db , json_level , true);
368
+ if (config -> master_user )
369
+ json_add_value (buf , "master-user" , config -> master_user , json_level ,
370
+ true);
371
+
372
+ if (config -> replica_timeout != INT_MIN )
373
+ {
374
+ json_add_key (buf , "replica-timeout" , json_level , true);
375
+ appendPQExpBuffer (buf , "%d" , config -> replica_timeout );
376
+ }
377
+
378
+ /* Logging parameters */
379
+ if (config -> log_level_console != INT_MIN )
380
+ json_add_value (buf , "log-level-console" ,
381
+ deparse_log_level (config -> log_level_console ), json_level ,
382
+ true);
383
+ if (config -> log_level_file != INT_MIN )
384
+ json_add_value (buf , "log-level-file" ,
385
+ deparse_log_level (config -> log_level_file ), json_level ,
386
+ true);
387
+ if (config -> log_filename )
388
+ json_add_value (buf , "log-filename" , config -> log_filename , json_level ,
389
+ true);
390
+ if (config -> error_log_filename )
391
+ json_add_value (buf , "error-log-filename" , config -> error_log_filename ,
392
+ json_level , true);
393
+ if (config -> log_directory )
394
+ json_add_value (buf , "log-directory" , config -> log_directory , json_level ,
395
+ true);
396
+
397
+ if (config -> log_rotation_size )
398
+ {
399
+ json_add_key (buf , "log-rotation-size" , json_level , true);
400
+ appendPQExpBuffer (buf , "%d" , config -> log_rotation_size );
401
+ }
402
+ if (config -> log_rotation_age )
403
+ {
404
+ json_add_key (buf , "log-rotation-age" , json_level , true);
405
+ appendPQExpBuffer (buf , "%d" , config -> log_rotation_age );
406
+ }
407
+
408
+ /* Retention parameters */
409
+ if (config -> retention_redundancy )
410
+ {
411
+ json_add_key (buf , "retention-redundancy" , json_level , true);
412
+ appendPQExpBuffer (buf , "%u" , config -> retention_redundancy );
413
+ }
414
+ if (config -> retention_window )
415
+ {
416
+ json_add_key (buf , "retention-window" , json_level , true);
417
+ appendPQExpBuffer (buf , "%u" , config -> retention_window );
418
+ }
419
+
420
+ /* Compression parameters */
421
+ json_add_value (buf , "compress-algorithm" ,
422
+ deparse_compress_alg (config -> compress_alg ), json_level ,
423
+ true);
424
+
425
+ json_add_key (buf , "compress-level" , json_level , true);
426
+ appendPQExpBuffer (buf , "%d" , config -> compress_level );
427
+
428
+ json_add (buf , JT_END_OBJECT , & json_level );
429
+ }
0 commit comments