@@ -164,6 +164,12 @@ int64 ttl = -1;
164
164
static char * expire_time_string = NULL ;
165
165
static pgSetBackupParams * set_backup_params = NULL ;
166
166
167
+ #ifdef PBCKP_S3
168
+ /* S3 options */
169
+ S3_protocol s3_protocol ;
170
+ char * s3_target_bucket = NULL ;
171
+ #endif
172
+
167
173
/* ================ backupState =========== */
168
174
static char * backup_id_string = NULL ;
169
175
pgBackup current ;
@@ -174,6 +180,9 @@ static bool help_opt = false;
174
180
static void opt_incr_restore_mode (ConfigOption * opt , const char * arg );
175
181
static void opt_backup_mode (ConfigOption * opt , const char * arg );
176
182
static void opt_show_format (ConfigOption * opt , const char * arg );
183
+ #ifdef PBCKP_S3
184
+ static void opt_s3_protocol (ConfigOption * opt , const char * arg );
185
+ #endif
177
186
178
187
static void compress_init (ProbackupSubcmd const subcmd );
179
188
@@ -270,6 +279,12 @@ static ConfigOption cmd_options[] =
270
279
{ 'I' , 170 , "ttl" , & ttl , SOURCE_CMD_STRICT , SOURCE_DEFAULT , 0 , OPTION_UNIT_S , option_get_value },
271
280
{ 's' , 171 , "expire-time" , & expire_time_string , SOURCE_CMD_STRICT },
272
281
282
+ #ifdef PBCKP_S3
283
+ /* S3 options */
284
+ { 'f' , 245 , "s3" , opt_s3_protocol , SOURCE_CMD_STRICT },
285
+ { 's' , 246 , "target-bucket" , & s3_target_bucket , SOURCE_CMD_STRICT },
286
+ #endif
287
+
273
288
/* options for backward compatibility
274
289
* TODO: remove in 3.0.0
275
290
*/
@@ -953,6 +968,19 @@ main(int argc, char *argv[])
953
968
954
969
compress_init (backup_subcmd );
955
970
971
+ #ifdef PBCKP_S3
972
+ if (s3_protocol != S3_INVALID_PROTOCOL )
973
+ {
974
+ char * s3_config_file = "" ;
975
+ read_s3_config (s3_config_file );
976
+ }
977
+ else
978
+ {
979
+ if (s3_target_bucket != NULL )
980
+ elog (WARNING , "You cannot specify s3-target without using --s3 option with name of protocol" );
981
+ }
982
+ #endif
983
+
956
984
/* do actual operation */
957
985
switch (backup_subcmd )
958
986
{
@@ -965,11 +993,27 @@ main(int argc, char *argv[])
965
993
wal_file_path , wal_file_name , batch_size , !no_validate_wal );
966
994
break ;
967
995
case ADD_INSTANCE_CMD :
968
- return do_add_instance (instanceState , & instance_config );
996
+ {
997
+ int err = 0 ;
998
+ err = do_add_instance (instanceState , & instance_config );
999
+ #ifdef PBCKP_S3
1000
+ if (err == 0 && s3_protocol != S3_INVALID_PROTOCOL )
1001
+ err = do_S3_write_config (instanceState );
1002
+ #endif
1003
+ return err ;
1004
+ }
969
1005
case DELETE_INSTANCE_CMD :
970
1006
return do_delete_instance (instanceState );
971
1007
case INIT_CMD :
972
- return do_init (catalogState );
1008
+ {
1009
+ int err = 0 ;
1010
+ err = do_init (catalogState );
1011
+ #ifdef PBCKP_S3
1012
+ if (err == 0 && s3_protocol != S3_INVALID_PROTOCOL )
1013
+ err = S3_pre_start_check (config );
1014
+ #endif
1015
+ return err ;
1016
+ }
973
1017
case BACKUP_CMD :
974
1018
{
975
1019
current .stream = stream_wal ;
@@ -984,13 +1028,21 @@ main(int argc, char *argv[])
984
1028
elog (ERROR , "required parameter not specified: BACKUP_MODE "
985
1029
"(-b, --backup-mode)" );
986
1030
1031
+ #ifdef PBCKP_S3
1032
+ if (s3_protocol != S3_INVALID_PROTOCOL )
1033
+ return do_S3_backup (instanceState , set_backup_params , start_time );
1034
+ #endif
987
1035
return do_backup (instanceState , set_backup_params ,
988
1036
no_validate , no_sync , backup_logs , start_time );
989
1037
}
990
1038
case CATCHUP_CMD :
991
1039
return do_catchup (catchup_source_pgdata , catchup_destination_pgdata , num_threads , !no_sync ,
992
1040
exclude_absolute_paths_list , exclude_relative_paths_list );
993
1041
case RESTORE_CMD :
1042
+ #ifdef PBCKP_S3
1043
+ if (s3_protocol != S3_INVALID_PROTOCOL )
1044
+ return do_S3_restore (instanceState , current .backup_id );
1045
+ #endif
994
1046
return do_restore_or_validate (instanceState , current .backup_id ,
995
1047
recovery_target_options ,
996
1048
restore_params , no_sync );
@@ -1010,6 +1062,10 @@ main(int argc, char *argv[])
1010
1062
restore_params ,
1011
1063
no_sync );
1012
1064
case SHOW_CMD :
1065
+ #ifdef PBCKP_S3
1066
+ if (s3_protocol != S3_INVALID_PROTOCOL )
1067
+ return do_S3_show (instanceState );
1068
+ #endif
1013
1069
return do_show (catalogState , instanceState , current .backup_id , show_archive );
1014
1070
case DELETE_CMD :
1015
1071
@@ -1198,3 +1254,34 @@ opt_exclude_path(ConfigOption *opt, const char *arg)
1198
1254
else
1199
1255
opt_parser_add_to_parray_helper (& exclude_relative_paths_list , arg );
1200
1256
}
1257
+
1258
+ #ifdef PBCKP_S3
1259
+ static S3_protocol
1260
+ parse_s3_protocol (const char * value )
1261
+ {
1262
+ const char * v = value ;
1263
+ size_t len ;
1264
+
1265
+ /* Skip all spaces detected */
1266
+ while (IsSpace (* v ))
1267
+ v ++ ;
1268
+ len = strlen (v );
1269
+
1270
+ if (len > 0 && pg_strncasecmp ("MINIO" , v , len ) == 0 )
1271
+ return S3_MINIO_PROTOCOL ;
1272
+ if (len > 0 && pg_strncasecmp ("AWS" , v , len ) == 0 )
1273
+ return S3_AWS_PROTOCOL ;
1274
+ else if (len > 0 && pg_strncasecmp ("GOOGLE" , v , len ) == 0 )
1275
+ return S3_GOOGLE_PROTOCOL ;
1276
+ else if (len > 0 && pg_strncasecmp ("VK" , v , len ) == 0 )
1277
+ return S3_VK_PROTOCOL ;
1278
+ else
1279
+ return S3_INVALID_PROTOCOL ;
1280
+ }
1281
+
1282
+ static void
1283
+ opt_s3_protocol (ConfigOption * opt , const char * arg )
1284
+ {
1285
+ s3_protocol = parse_s3_protocol (arg );
1286
+ }
1287
+ #endif
0 commit comments