@@ -21,34 +21,35 @@ const char *PROGRAM_URL = "https://github.com/postgrespro/pg_probackup";
21
21
const char * PROGRAM_EMAIL = "https://github.com/postgrespro/pg_probackup/issues" ;
22
22
23
23
/* path configuration */
24
- char * backup_path ;
25
- char * pgdata ;
26
- char arclog_path [MAXPGPATH ];
24
+ char * backup_path = NULL ;
25
+ char * pgdata = NULL ;
26
+ char arclog_path [MAXPGPATH ] = "" ;
27
27
28
28
/* directory configuration */
29
29
pgBackup current ;
30
- ProbackupSubcmd backup_subcmd ;
30
+ ProbackupSubcmd backup_subcmd ;
31
31
32
- bool help = false;
32
+ bool help = false;
33
33
34
- char * backup_id_string_param = NULL ;
35
- bool backup_logs = false;
34
+ char * backup_id_string_param = NULL ;
35
+ bool backup_logs = false;
36
36
37
- bool smooth_checkpoint ;
38
- int num_threads = 1 ;
39
- bool stream_wal = false;
40
- bool from_replica = false;
41
- bool progress = false;
42
- bool delete_wal = false;
43
- bool delete_expired = false;
44
- bool apply_to_all = false;
45
- bool force_delete = false;
46
- uint32 archive_timeout = 300 ; /* Wait timeout for WAL segment archiving */
37
+ bool smooth_checkpoint ;
38
+ int num_threads = 1 ;
39
+ bool stream_wal = false;
40
+ bool from_replica = false;
41
+ bool progress = false;
42
+ bool delete_wal = false;
43
+ bool delete_expired = false;
44
+ bool apply_to_all = false;
45
+ bool force_delete = false;
46
+ /* Wait timeout for WAL segment archiving */
47
+ uint32 archive_timeout = 300 ;
47
48
48
- uint64 system_identifier = 0 ;
49
+ uint64 system_identifier = 0 ;
49
50
50
- uint32 retention_redundancy = 0 ;
51
- uint32 retention_window = 0 ;
51
+ uint32 retention_redundancy = 0 ;
52
+ uint32 retention_window = 0 ;
52
53
53
54
/* restore configuration */
54
55
static char * target_time ;
@@ -57,48 +58,56 @@ static char *target_inclusive;
57
58
static TimeLineID target_tli ;
58
59
59
60
static void opt_backup_mode (pgut_option * opt , const char * arg );
61
+ static void opt_log_level (pgut_option * opt , const char * arg );
60
62
61
63
static pgut_option options [] =
62
64
{
63
65
/* directory options */
64
- { 'b' , 1 , "help" , & help , SOURCE_CMDLINE },
65
- { 's' , 'D' , "pgdata" , & pgdata , SOURCE_CMDLINE },
66
- { 's' , 'B' , "backup-path" , & backup_path , SOURCE_CMDLINE },
66
+ { 'b' , 1 , "help" , & help , SOURCE_CMDLINE },
67
+ { 's' , 'D' , "pgdata" , & pgdata , SOURCE_CMDLINE },
68
+ { 's' , 'B' , "backup-path" , & backup_path , SOURCE_CMDLINE },
67
69
/* common options */
68
- { 'u' , 'j' , "threads" , & num_threads , SOURCE_CMDLINE },
69
- { 'b' , 8 , "stream" , & stream_wal , SOURCE_CMDLINE },
70
- { 'b' , 11 , "progress" , & progress , SOURCE_CMDLINE },
70
+ { 'u' , 'j' , "threads" , & num_threads , SOURCE_CMDLINE },
71
+ { 'b' , 1 , "stream" , & stream_wal , SOURCE_CMDLINE },
72
+ { 'b' , 2 , "progress" , & progress , SOURCE_CMDLINE },
71
73
{ 's' , 'i' , "backup-id" , & backup_id_string_param , SOURCE_CMDLINE },
72
74
/* backup options */
73
- { 'b' , 10 , "backup-pg-log" , & backup_logs , SOURCE_CMDLINE },
75
+ { 'b' , 10 , "backup-pg-log" , & backup_logs , SOURCE_CMDLINE },
74
76
{ 'f' , 'b' , "backup-mode" , opt_backup_mode , SOURCE_CMDLINE },
75
77
{ 'b' , 'C' , "smooth-checkpoint" , & smooth_checkpoint , SOURCE_CMDLINE },
76
78
{ 's' , 'S' , "slot" , & replication_slot , SOURCE_CMDLINE },
77
- { 'u' , 2 , "archive-timeout" , & archive_timeout , SOURCE_CMDLINE },
78
- { 'b' , 19 , "delete-expired" , & delete_expired , SOURCE_CMDLINE },
79
+ { 'u' , 11 , "archive-timeout" , & archive_timeout , SOURCE_CMDLINE },
80
+ { 'b' , 12 , "delete-expired" , & delete_expired , SOURCE_CMDLINE },
79
81
/* restore options */
80
- { 's' , 3 , "time" , & target_time , SOURCE_CMDLINE },
81
- { 's' , 4 , "xid" , & target_xid , SOURCE_CMDLINE },
82
- { 's' , 5 , "inclusive" , & target_inclusive , SOURCE_CMDLINE },
83
- { 'u' , 6 , "timeline" , & target_tli , SOURCE_CMDLINE },
82
+ { 's' , 20 , "time" , & target_time , SOURCE_CMDLINE },
83
+ { 's' , 21 , "xid" , & target_xid , SOURCE_CMDLINE },
84
+ { 's' , 22 , "inclusive" , & target_inclusive , SOURCE_CMDLINE },
85
+ { 'u' , 23 , "timeline" , & target_tli , SOURCE_CMDLINE },
84
86
{ 'f' , 'T' , "tablespace-mapping" , opt_tablespace_map , SOURCE_CMDLINE },
85
87
/* delete options */
86
- { 'b' , 12 , "wal" , & delete_wal , SOURCE_CMDLINE },
87
- { 'b' , 16 , "expired" , & delete_expired , SOURCE_CMDLINE },
88
- { 'b' , 17 , "all" , & apply_to_all , SOURCE_CMDLINE },
88
+ { 'b' , 30 , "wal" , & delete_wal , SOURCE_CMDLINE },
89
+ { 'b' , 31 , "expired" , & delete_expired , SOURCE_CMDLINE },
90
+ { 'b' , 32 , "all" , & apply_to_all , SOURCE_CMDLINE },
89
91
/* TODO not implemented yet */
90
- { 'b' , 18 , "force" , & force_delete , SOURCE_CMDLINE },
91
- /* configure options */
92
- { 'u' , 13 , "retention-redundancy" , & retention_redundancy , SOURCE_CMDLINE },
93
- { 'u' , 14 , "retention-window" , & retention_window , SOURCE_CMDLINE },
94
- /* other */
95
- { 'U' , 15 , "system-identifier" , & system_identifier , SOURCE_FILE_STRICT },
96
-
97
- { 's' , 'd' , "pgdatabase" , & pgut_dbname , SOURCE_CMDLINE },
98
- { 's' , 'h' , "pghost" , & host , SOURCE_CMDLINE },
99
- { 's' , 'p' , "pgport" , & port , SOURCE_CMDLINE },
100
- { 's' , 'U' , "pguser" , & username , SOURCE_CMDLINE },
101
- { 'B' , 'w' , "no-password" , & prompt_password , SOURCE_CMDLINE },
92
+ { 'b' , 33 , "force" , & force_delete , SOURCE_CMDLINE },
93
+ /* retention options */
94
+ { 'u' , 34 , "retention-redundancy" , & retention_redundancy , SOURCE_CMDLINE },
95
+ { 'u' , 35 , "retention-window" , & retention_window , SOURCE_CMDLINE },
96
+ /* logging options */
97
+ { 'f' , 40 , "log-level" , opt_log_level , SOURCE_CMDLINE },
98
+ { 's' , 41 , "log-filename" , & log_filename , SOURCE_CMDLINE },
99
+ { 's' , 42 , "error-log-filename" , & error_log_filename , SOURCE_CMDLINE },
100
+ { 's' , 43 , "log-directory" , & log_directory , SOURCE_CMDLINE },
101
+ { 'u' , 44 , "log-rotation-size" , & log_rotation_size , SOURCE_CMDLINE },
102
+ { 'u' , 45 , "log-rotation-age" , & log_rotation_age , SOURCE_CMDLINE },
103
+ /* connection options */
104
+ { 's' , 'd' , "pgdatabase" , & pgut_dbname , SOURCE_CMDLINE },
105
+ { 's' , 'h' , "pghost" , & host , SOURCE_CMDLINE },
106
+ { 's' , 'p' , "pgport" , & port , SOURCE_CMDLINE },
107
+ { 's' , 'U' , "pguser" , & username , SOURCE_CMDLINE },
108
+ { 'B' , 'w' , "no-password" , & prompt_password , SOURCE_CMDLINE },
109
+ /* other options */
110
+ { 'U' , 50 , "system-identifier" , & system_identifier , SOURCE_FILE_STRICT },
102
111
{ 0 }
103
112
};
104
113
@@ -202,6 +211,15 @@ main(int argc, char *argv[])
202
211
if (!is_absolute_path (backup_path ))
203
212
elog (ERROR , "-B, --backup-path must be an absolute path" );
204
213
214
+ /* Set log path */
215
+ if (log_filename || error_log_filename )
216
+ {
217
+ if (log_directory )
218
+ join_path_components (log_path , backup_path , log_directory );
219
+ else
220
+ join_path_components (log_path , backup_path , "log" );
221
+ }
222
+
205
223
if (backup_id_string_param != NULL )
206
224
{
207
225
current .backup_id = base36dec (backup_id_string_param );
@@ -228,9 +246,6 @@ main(int argc, char *argv[])
228
246
229
247
join_path_components (arclog_path , backup_path , "wal" );
230
248
231
- log_filename = "pg_probackup-%Y-%m-%d_%H%M%S.log" ;
232
- join_path_components (log_path , backup_path , "log" );
233
-
234
249
/* setup exclusion list for file search */
235
250
if (!backup_logs )
236
251
{
@@ -292,3 +307,9 @@ opt_backup_mode(pgut_option *opt, const char *arg)
292
307
{
293
308
current .backup_mode = parse_backup_mode (arg );
294
309
}
310
+
311
+ static void
312
+ opt_log_level (pgut_option * opt , const char * arg )
313
+ {
314
+ log_level = parse_log_level (arg );
315
+ }
0 commit comments