8
8
*/
9
9
10
10
#include "pg_probackup.h"
11
+ #include "utils/logger.h"
11
12
12
13
#include "pqexpbuffer.h"
13
14
@@ -57,13 +58,17 @@ do_configure(bool show_only)
57
58
config -> master_db = master_db ;
58
59
if (master_user )
59
60
config -> master_user = master_user ;
60
- if (replica_timeout != 300 ) /* 300 is default value */
61
+
62
+ if (replica_timeout )
61
63
config -> replica_timeout = replica_timeout ;
62
64
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 ;
67
72
if (log_filename )
68
73
config -> log_filename = log_filename ;
69
74
if (error_log_filename )
@@ -80,9 +85,9 @@ do_configure(bool show_only)
80
85
if (retention_window )
81
86
config -> retention_window = retention_window ;
82
87
83
- if (compress_alg != NOT_DEFINED_COMPRESS )
88
+ if (compress_alg )
84
89
config -> compress_alg = compress_alg ;
85
- if (compress_level != DEFAULT_COMPRESS_LEVEL )
90
+ if (compress_level )
86
91
config -> compress_level = compress_level ;
87
92
88
93
if (show_only )
@@ -107,21 +112,23 @@ pgBackupConfigInit(pgBackupConfig *config)
107
112
config -> master_port = NULL ;
108
113
config -> master_db = NULL ;
109
114
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 ;
111
118
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 ;
115
122
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 ;
119
126
120
- config -> retention_redundancy = 0 ;
121
- config -> retention_window = 0 ;
127
+ config -> retention_redundancy = RETENTION_REDUNDANCY_DEFAULT ;
128
+ config -> retention_window = RETENTION_WINDOW_DEFAULT ;
122
129
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 ;
125
132
}
126
133
127
134
void
@@ -154,55 +161,43 @@ writeBackupCatalogConfig(FILE *out, pgBackupConfig *config)
154
161
if (config -> master_user )
155
162
fprintf (out , "master-user = %s\n" , config -> master_user );
156
163
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 );
163
172
164
173
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 );
171
177
if (config -> error_log_filename )
172
178
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
174
183
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" );
175
188
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" );
191
192
192
193
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 );
197
196
198
197
fprintf (out , "#Compression parameters:\n" );
199
198
200
199
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 );
206
201
}
207
202
208
203
void
@@ -258,6 +253,8 @@ readBackupCatalogConfigFile(void)
258
253
{ 'u' , 0 , "replica-timeout" , & (config -> replica_timeout ), SOURCE_CMDLINE , SOURCE_DEFAULT , OPTION_UNIT_S },
259
254
/* other options */
260
255
{ '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 },
261
258
{0 }
262
259
};
263
260
@@ -342,6 +339,8 @@ static void
342
339
show_configure_json (pgBackupConfig * config )
343
340
{
344
341
PQExpBuffer buf = & show_buf ;
342
+ uint64 res ;
343
+ const char * unit ;
345
344
346
345
json_add (buf , JT_BEGIN_OBJECT , & json_level );
347
346
@@ -373,53 +372,60 @@ show_configure_json(pgBackupConfig *config)
373
372
json_add_value (buf , "master-user" , config -> master_user , json_level ,
374
373
true);
375
374
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 );
381
385
382
386
/* 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);
394
395
if (config -> error_log_filename )
395
396
json_add_value (buf , "error-log-filename" , config -> error_log_filename ,
396
397
json_level , true);
397
- if (config -> log_directory )
398
- json_add_value (buf , "log-directory" , config -> log_directory , json_level ,
399
- true);
400
398
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 )
407
400
{
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);
410
408
}
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" );
411
422
412
423
/* 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 );
423
429
424
430
/* Compression parameters */
425
431
json_add_value (buf , "compress-algorithm" ,
0 commit comments