88 */
99
1010#include "pg_probackup.h"
11+ #include "utils/logger.h"
1112
1213#include "pqexpbuffer.h"
1314
@@ -57,13 +58,17 @@ do_configure(bool show_only)
5758 config -> master_db = master_db ;
5859 if (master_user )
5960 config -> master_user = master_user ;
60- if (replica_timeout != 300 ) /* 300 is default value */
61+
62+ if (replica_timeout )
6163 config -> replica_timeout = replica_timeout ;
6264
63- if (log_level_console != LOG_NONE )
64- config -> log_level_console = LOG_LEVEL_CONSOLE ;
65- if (log_level_file != LOG_NONE )
66- config -> log_level_file = LOG_LEVEL_FILE ;
65+ if (archive_timeout )
66+ config -> archive_timeout = archive_timeout ;
67+
68+ if (log_level_console )
69+ config -> log_level_console = log_level_console ;
70+ if (log_level_file )
71+ config -> log_level_file = log_level_file ;
6772 if (log_filename )
6873 config -> log_filename = log_filename ;
6974 if (error_log_filename )
@@ -80,9 +85,9 @@ do_configure(bool show_only)
8085 if (retention_window )
8186 config -> retention_window = retention_window ;
8287
83- if (compress_alg != NOT_DEFINED_COMPRESS )
88+ if (compress_alg )
8489 config -> compress_alg = compress_alg ;
85- if (compress_level != DEFAULT_COMPRESS_LEVEL )
90+ if (compress_level )
8691 config -> compress_level = compress_level ;
8792
8893 if (show_only )
@@ -107,21 +112,23 @@ pgBackupConfigInit(pgBackupConfig *config)
107112 config -> master_port = NULL ;
108113 config -> master_db = NULL ;
109114 config -> master_user = NULL ;
110- config -> replica_timeout = INT_MIN ; /* INT_MIN means "undefined" */
115+ config -> replica_timeout = REPLICA_TIMEOUT_DEFAULT ;
116+
117+ config -> archive_timeout = ARCHIVE_TIMEOUT_DEFAULT ;
111118
112- config -> log_level_console = INT_MIN ; /* INT_MIN means "undefined" */
113- config -> log_level_file = INT_MIN ; /* INT_MIN means "undefined" */
114- config -> log_filename = NULL ;
119+ config -> log_level_console = LOG_LEVEL_CONSOLE_DEFAULT ;
120+ config -> log_level_file = LOG_LEVEL_FILE_DEFAULT ;
121+ config -> log_filename = LOG_FILENAME_DEFAULT ;
115122 config -> error_log_filename = NULL ;
116- config -> log_directory = NULL ;
117- config -> log_rotation_size = 0 ;
118- config -> log_rotation_age = 0 ;
123+ config -> log_directory = LOG_DIRECTORY_DEFAULT ;
124+ config -> log_rotation_size = LOG_ROTATION_SIZE_DEFAULT ;
125+ config -> log_rotation_age = LOG_ROTATION_AGE_DEFAULT ;
119126
120- config -> retention_redundancy = 0 ;
121- config -> retention_window = 0 ;
127+ config -> retention_redundancy = RETENTION_REDUNDANCY_DEFAULT ;
128+ config -> retention_window = RETENTION_WINDOW_DEFAULT ;
122129
123- config -> compress_alg = NOT_DEFINED_COMPRESS ;
124- config -> compress_level = DEFAULT_COMPRESS_LEVEL ;
130+ config -> compress_alg = COMPRESS_ALG_DEFAULT ;
131+ config -> compress_level = COMPRESS_LEVEL_DEFAULT ;
125132}
126133
127134void
@@ -154,55 +161,43 @@ writeBackupCatalogConfig(FILE *out, pgBackupConfig *config)
154161 if (config -> master_user )
155162 fprintf (out , "master-user = %s\n" , config -> master_user );
156163
157- if (config -> replica_timeout != INT_MIN )
158- {
159- convert_from_base_unit_u (config -> replica_timeout , OPTION_UNIT_S ,
160- & res , & unit );
161- fprintf (out , "replica-timeout = " UINT64_FORMAT "%s\n" , res , unit );
162- }
164+ convert_from_base_unit_u (config -> replica_timeout , OPTION_UNIT_S ,
165+ & res , & unit );
166+ fprintf (out , "replica-timeout = " UINT64_FORMAT "%s\n" , res , unit );
167+
168+ fprintf (out , "#Archive parameters:\n" );
169+ convert_from_base_unit_u (config -> archive_timeout , OPTION_UNIT_S ,
170+ & res , & unit );
171+ fprintf (out , "archive-timeout = " UINT64_FORMAT "%s\n" , res , unit );
163172
164173 fprintf (out , "#Logging parameters:\n" );
165- if (config -> log_level_console != INT_MIN )
166- fprintf (out , "log-level-console = %s\n" , deparse_log_level (config -> log_level_console ));
167- if (config -> log_level_file != INT_MIN )
168- fprintf (out , "log-level-file = %s\n" , deparse_log_level (config -> log_level_file ));
169- if (config -> log_filename )
170- fprintf (out , "log-filename = %s\n" , config -> log_filename );
174+ fprintf (out , "log-level-console = %s\n" , deparse_log_level (config -> log_level_console ));
175+ fprintf (out , "log-level-file = %s\n" , deparse_log_level (config -> log_level_file ));
176+ fprintf (out , "log-filename = %s\n" , config -> log_filename );
171177 if (config -> error_log_filename )
172178 fprintf (out , "error-log-filename = %s\n" , config -> error_log_filename );
173- if (config -> log_directory )
179+
180+ if (strcmp (config -> log_directory , LOG_DIRECTORY_DEFAULT ) == 0 )
181+ fprintf (out , "log-directory = %s/%s\n" , backup_path , config -> log_directory );
182+ else
174183 fprintf (out , "log-directory = %s\n" , config -> log_directory );
184+ /* Convert values from base unit */
185+ convert_from_base_unit_u (config -> log_rotation_size , OPTION_UNIT_KB ,
186+ & res , & unit );
187+ fprintf (out , "log-rotation-size = " UINT64_FORMAT "%s\n" , res , (res )?unit :"KB" );
175188
176- /*
177- * Convert values from base unit
178- */
179- if (config -> log_rotation_size )
180- {
181- convert_from_base_unit_u (config -> log_rotation_size , OPTION_UNIT_KB ,
182- & res , & unit );
183- fprintf (out , "log-rotation-size = " UINT64_FORMAT "%s\n" , res , unit );
184- }
185- if (config -> log_rotation_age )
186- {
187- convert_from_base_unit_u (config -> log_rotation_age , OPTION_UNIT_S ,
188- & res , & unit );
189- fprintf (out , "log-rotation-age = " UINT64_FORMAT "%s\n" , res , unit );
190- }
189+ convert_from_base_unit_u (config -> log_rotation_age , OPTION_UNIT_S ,
190+ & res , & unit );
191+ fprintf (out , "log-rotation-age = " UINT64_FORMAT "%s\n" , res , (res )?unit :"min" );
191192
192193 fprintf (out , "#Retention parameters:\n" );
193- if (config -> retention_redundancy )
194- fprintf (out , "retention-redundancy = %u\n" , config -> retention_redundancy );
195- if (config -> retention_window )
196- fprintf (out , "retention-window = %u\n" , config -> retention_window );
194+ fprintf (out , "retention-redundancy = %u\n" , config -> retention_redundancy );
195+ fprintf (out , "retention-window = %u\n" , config -> retention_window );
197196
198197 fprintf (out , "#Compression parameters:\n" );
199198
200199 fprintf (out , "compress-algorithm = %s\n" , deparse_compress_alg (config -> compress_alg ));
201-
202- if (compress_level != config -> compress_level )
203- fprintf (out , "compress-level = %d\n" , compress_level );
204- else
205- fprintf (out , "compress-level = %d\n" , config -> compress_level );
200+ fprintf (out , "compress-level = %d\n" , config -> compress_level );
206201}
207202
208203void
@@ -258,6 +253,8 @@ readBackupCatalogConfigFile(void)
258253 { 'u' , 0 , "replica-timeout" , & (config -> replica_timeout ), SOURCE_CMDLINE , SOURCE_DEFAULT , OPTION_UNIT_S },
259254 /* other options */
260255 { 'U' , 0 , "system-identifier" , & (config -> system_identifier ), SOURCE_FILE_STRICT },
256+ /* archive options */
257+ { 'u' , 0 , "archive-timeout" , & (config -> archive_timeout ), SOURCE_CMDLINE , SOURCE_DEFAULT , OPTION_UNIT_S },
261258 {0 }
262259 };
263260
@@ -342,6 +339,8 @@ static void
342339show_configure_json (pgBackupConfig * config )
343340{
344341 PQExpBuffer buf = & show_buf ;
342+ uint64 res ;
343+ const char * unit ;
345344
346345 json_add (buf , JT_BEGIN_OBJECT , & json_level );
347346
@@ -373,53 +372,60 @@ show_configure_json(pgBackupConfig *config)
373372 json_add_value (buf , "master-user" , config -> master_user , json_level ,
374373 true);
375374
376- if (config -> replica_timeout != INT_MIN )
377- {
378- json_add_key (buf , "replica-timeout" , json_level , true);
379- appendPQExpBuffer (buf , "%d" , config -> replica_timeout );
380- }
375+ json_add_key (buf , "replica-timeout" , json_level , true);
376+ convert_from_base_unit_u (config -> replica_timeout , OPTION_UNIT_S ,
377+ & res , & unit );
378+ appendPQExpBuffer (buf , UINT64_FORMAT "%s" , res , unit );
379+
380+ /* Archive parameters */
381+ json_add_key (buf , "archive-timeout" , json_level , true);
382+ convert_from_base_unit_u (config -> archive_timeout , OPTION_UNIT_S ,
383+ & res , & unit );
384+ appendPQExpBuffer (buf , UINT64_FORMAT "%s" , res , unit );
381385
382386 /* Logging parameters */
383- if (config -> log_level_console != INT_MIN )
384- json_add_value (buf , "log-level-console" ,
385- deparse_log_level (config -> log_level_console ), json_level ,
386- true);
387- if (config -> log_level_file != INT_MIN )
388- json_add_value (buf , "log-level-file" ,
389- deparse_log_level (config -> log_level_file ), json_level ,
390- true);
391- if (config -> log_filename )
392- json_add_value (buf , "log-filename" , config -> log_filename , json_level ,
393- true);
387+ json_add_value (buf , "log-level-console" ,
388+ deparse_log_level (config -> log_level_console ), json_level ,
389+ true);
390+ json_add_value (buf , "log-level-file" ,
391+ deparse_log_level (config -> log_level_file ), json_level ,
392+ true);
393+ json_add_value (buf , "log-filename" , config -> log_filename , json_level ,
394+ true);
394395 if (config -> error_log_filename )
395396 json_add_value (buf , "error-log-filename" , config -> error_log_filename ,
396397 json_level , true);
397- if (config -> log_directory )
398- json_add_value (buf , "log-directory" , config -> log_directory , json_level ,
399- true);
400398
401- if (config -> log_rotation_size )
402- {
403- json_add_key (buf , "log-rotation-size" , json_level , true);
404- appendPQExpBuffer (buf , "%d" , config -> log_rotation_size );
405- }
406- if (config -> log_rotation_age )
399+ if (strcmp (config -> log_directory , LOG_DIRECTORY_DEFAULT ) == 0 )
407400 {
408- json_add_key (buf , "log-rotation-age" , json_level , true);
409- appendPQExpBuffer (buf , "%d" , config -> log_rotation_age );
401+ char log_directory_fullpath [MAXPGPATH ];
402+
403+ sprintf (log_directory_fullpath , "%s/%s" ,
404+ backup_path , config -> log_directory );
405+
406+ json_add_value (buf , "log-directory" , log_directory_fullpath ,
407+ json_level , true);
410408 }
409+ else
410+ json_add_value (buf , "log-directory" , config -> log_directory ,
411+ json_level , true);
412+
413+ json_add_key (buf , "log-rotation-size" , json_level , true);
414+ convert_from_base_unit_u (config -> log_rotation_size , OPTION_UNIT_KB ,
415+ & res , & unit );
416+ appendPQExpBuffer (buf , UINT64_FORMAT "%s" , res , (res )?unit :"KB" );
417+
418+ json_add_key (buf , "log-rotation-age" , json_level , true);
419+ convert_from_base_unit_u (config -> log_rotation_age , OPTION_UNIT_S ,
420+ & res , & unit );
421+ appendPQExpBuffer (buf , UINT64_FORMAT "%s" , res , (res )?unit :"min" );
411422
412423 /* Retention parameters */
413- if (config -> retention_redundancy )
414- {
415- json_add_key (buf , "retention-redundancy" , json_level , true);
416- appendPQExpBuffer (buf , "%u" , config -> retention_redundancy );
417- }
418- if (config -> retention_window )
419- {
420- json_add_key (buf , "retention-window" , json_level , true);
421- appendPQExpBuffer (buf , "%u" , config -> retention_window );
422- }
424+ json_add_key (buf , "retention-redundancy" , json_level , true);
425+ appendPQExpBuffer (buf , "%u" , config -> retention_redundancy );
426+
427+ json_add_key (buf , "retention-window" , json_level , true);
428+ appendPQExpBuffer (buf , "%u" , config -> retention_window );
423429
424430 /* Compression parameters */
425431 json_add_value (buf , "compress-algorithm" ,
0 commit comments