@@ -84,6 +84,14 @@ static pgut_option options[] =
84
84
{ 'u' , 14 , "window" , & retention_window , SOURCE_CMDLINE },
85
85
/* other */
86
86
{ 'U' , 15 , "system-identifier" , & system_identifier , SOURCE_FILE_STRICT },
87
+
88
+ { 's' , 'd' , "dbname" , & pgut_dbname , SOURCE_CMDLINE },
89
+ { 's' , 'h' , "host" , & host , SOURCE_CMDLINE },
90
+ { 's' , 'p' , "port" , & port , SOURCE_CMDLINE },
91
+ { 'b' , 'q' , "quiet" , & quiet , SOURCE_CMDLINE },
92
+ { 's' , 'U' , "username" , & username , SOURCE_CMDLINE },
93
+ { 'b' , 'v' , "verbose" , & verbose , SOURCE_CMDLINE },
94
+ { 'B' , 'w' , "no-password" , & prompt_password , SOURCE_CMDLINE },
87
95
{ 0 }
88
96
};
89
97
@@ -93,52 +101,49 @@ static pgut_option options[] =
93
101
int
94
102
main (int argc , char * argv [])
95
103
{
96
- const char * cmd = NULL ,
97
- * subcmd = NULL ;
98
- const char * backup_id_string = NULL ;
104
+ ProbackupSubcmd backup_subcmd ;
99
105
time_t backup_id = 0 ;
100
106
int i ;
101
107
102
- /* do not buffer progress messages */
103
- setvbuf (stdout , 0 , _IONBF , 0 ); /* TODO: remove this */
104
-
105
108
/* initialize configuration */
106
109
init_backup (& current );
107
110
108
- /* overwrite configuration with command line arguments */
109
- i = pgut_getopt ( argc , argv , options );
111
+ PROGRAM_NAME = get_progname ( argv [ 0 ]);
112
+ set_pglocale_pgservice ( argv [ 0 ], "pgscripts" );
110
113
111
- for (; i < argc ; i ++ )
114
+ /* Parse subcommands and non-subcommand options */
115
+ if (argc > 1 )
112
116
{
113
- if (cmd == NULL )
114
- cmd = argv [i ];
115
- else if (strcmp (cmd , "retention" ) == 0 )
116
- subcmd = argv [i ];
117
- else if (backup_id_string == NULL &&
118
- (strcmp (cmd , "show" ) == 0 ||
119
- strcmp (cmd , "validate" ) == 0 ||
120
- strcmp (cmd , "delete" ) == 0 ||
121
- strcmp (cmd , "restore" ) == 0 ||
122
- strcmp (cmd , "delwal" ) == 0 ))
123
- backup_id_string = argv [i ];
117
+ if (strcmp (argv [1 ], "init" ) == 0 )
118
+ backup_subcmd = INIT ;
119
+ else if (strcmp (argv [1 ], "backup" ) == 0 )
120
+ backup_subcmd = BACKUP ;
121
+ else if (strcmp (argv [1 ], "restore" ) == 0 )
122
+ backup_subcmd = RESTORE ;
123
+ else if (strcmp (argv [1 ], "validate" ) == 0 )
124
+ backup_subcmd = VALIDATE ;
125
+ else if (strcmp (argv [1 ], "show" ) == 0 )
126
+ backup_subcmd = SHOW ;
127
+ else if (strcmp (argv [1 ], "delete" ) == 0 )
128
+ backup_subcmd = DELETE ;
129
+ else if (strcmp (argv [1 ], "configure" ) == 0 )
130
+ backup_subcmd = CONFIGURE ;
131
+ else if (strcmp (argv [1 ], "--help" ) == 0 || strcmp (argv [1 ], "-?" ) == 0 )
132
+ {
133
+ help (true);
134
+ exit (0 );
135
+ }
136
+ else if (strcmp (argv [1 ], "--version" ) == 0 || strcmp (argv [1 ], "-V" ) == 0 )
137
+ {
138
+ fprintf (stderr , "%s %s\n" , PROGRAM_NAME , PROGRAM_VERSION );
139
+ exit (0 );
140
+ }
124
141
else
125
- elog (ERROR , "too many arguments" );
126
- }
127
-
128
- /* command argument (backup/restore/show/...) is required. */
129
- if (cmd == NULL )
130
- {
131
- help (false);
132
- return 1 ;
142
+ elog (ERROR , "Invalid subcommand" );
133
143
}
134
144
135
- if (backup_id_string != NULL )
136
- {
137
- backup_id = base36dec (backup_id_string );
138
- if (backup_id == 0 ) {
139
- elog (ERROR , "wrong ID" );
140
- }
141
- }
145
+ /* Parse command line arguments */
146
+ i = pgut_getopt (argc , argv , options );
142
147
143
148
/* BACKUP_PATH is always required */
144
149
if (backup_path == NULL )
@@ -189,39 +194,41 @@ main(int argc, char *argv[])
189
194
num_threads = 1 ;
190
195
191
196
/* do actual operation */
192
- if (pg_strcasecmp (cmd , "init" ) == 0 )
193
- return do_init ();
194
- else if (pg_strcasecmp (cmd , "backup" ) == 0 )
195
- return do_backup (smooth_checkpoint );
196
- else if (pg_strcasecmp (cmd , "restore" ) == 0 )
197
- return do_restore (backup_id ,
197
+ switch (backup_subcmd )
198
+ {
199
+ case INIT :
200
+ return do_init ();
201
+ case BACKUP :
202
+ return do_backup (smooth_checkpoint );
203
+ case RESTORE :
204
+ return do_restore (backup_id ,
198
205
target_time ,
199
206
target_xid ,
200
207
target_inclusive ,
201
208
target_tli );
202
- else if (pg_strcasecmp (cmd , "show" ) == 0 )
203
- return do_show (backup_id );
204
- else if (pg_strcasecmp (cmd , "validate" ) == 0 )
205
- return do_validate (backup_id ,
209
+ case VALIDATE :
210
+ return do_validate (backup_id ,
206
211
target_time ,
207
212
target_xid ,
208
213
target_inclusive ,
209
214
target_tli );
210
- else if (pg_strcasecmp (cmd , "delete" ) == 0 )
211
- return do_delete (backup_id );
212
- else if (pg_strcasecmp (cmd , "delwal" ) == 0 )
213
- return do_deletewal (backup_id , true, true);
214
- else if (pg_strcasecmp (cmd , "retention" ) == 0 )
215
- {
216
- if (subcmd == NULL )
217
- elog (ERROR , "you must specify retention command" );
218
- else if (pg_strcasecmp (subcmd , "show" ) == 0 )
219
- return do_retention_show ();
220
- else if (pg_strcasecmp (subcmd , "purge" ) == 0 )
221
- return do_retention_purge ();
215
+ case SHOW :
216
+ return do_show (backup_id );
217
+ case DELETE :
218
+ return do_delete (backup_id );
219
+ case CONFIGURE :
220
+ elog (ERROR , "not implemented yet" );
222
221
}
223
- else
224
- elog (ERROR , "invalid command \"%s\"" , cmd );
222
+
223
+ // if (pg_strcasecmp(cmd, "retention") == 0)
224
+ // {
225
+ // if (subcmd == NULL)
226
+ // elog(ERROR, "you must specify retention command");
227
+ // else if (pg_strcasecmp(subcmd, "show") == 0)
228
+ // return do_retention_show();
229
+ // else if (pg_strcasecmp(subcmd, "purge") == 0)
230
+ // return do_retention_purge();
231
+ // }
225
232
226
233
return 0 ;
227
234
}
0 commit comments