@@ -164,6 +164,12 @@ int64 ttl = -1;
164164static char * expire_time_string = NULL ;
165165static pgSetBackupParams * set_backup_params = NULL ;
166166
167+ #ifdef PBCKP_S3
168+ /* S3 options */
169+ S3_protocol s3_protocol ;
170+ char * s3_target_bucket = NULL ;
171+ #endif
172+
167173/* ================ backupState =========== */
168174static char * backup_id_string = NULL ;
169175pgBackup current ;
@@ -174,6 +180,9 @@ static bool help_opt = false;
174180static void opt_incr_restore_mode (ConfigOption * opt , const char * arg );
175181static void opt_backup_mode (ConfigOption * opt , const char * arg );
176182static 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
177186
178187static void compress_init (ProbackupSubcmd const subcmd );
179188
@@ -270,6 +279,12 @@ static ConfigOption cmd_options[] =
270279 { 'I' , 170 , "ttl" , & ttl , SOURCE_CMD_STRICT , SOURCE_DEFAULT , 0 , OPTION_UNIT_S , option_get_value },
271280 { 's' , 171 , "expire-time" , & expire_time_string , SOURCE_CMD_STRICT },
272281
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+
273288 /* options for backward compatibility
274289 * TODO: remove in 3.0.0
275290 */
@@ -953,6 +968,19 @@ main(int argc, char *argv[])
953968
954969 compress_init (backup_subcmd );
955970
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+
956984 /* do actual operation */
957985 switch (backup_subcmd )
958986 {
@@ -965,11 +993,27 @@ main(int argc, char *argv[])
965993 wal_file_path , wal_file_name , batch_size , !no_validate_wal );
966994 break ;
967995 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+ }
9691005 case DELETE_INSTANCE_CMD :
9701006 return do_delete_instance (instanceState );
9711007 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+ }
9731017 case BACKUP_CMD :
9741018 {
9751019 current .stream = stream_wal ;
@@ -984,13 +1028,21 @@ main(int argc, char *argv[])
9841028 elog (ERROR , "required parameter not specified: BACKUP_MODE "
9851029 "(-b, --backup-mode)" );
9861030
1031+ #ifdef PBCKP_S3
1032+ if (s3_protocol != S3_INVALID_PROTOCOL )
1033+ return do_S3_backup (instanceState , set_backup_params , start_time );
1034+ #endif
9871035 return do_backup (instanceState , set_backup_params ,
9881036 no_validate , no_sync , backup_logs , start_time );
9891037 }
9901038 case CATCHUP_CMD :
9911039 return do_catchup (catchup_source_pgdata , catchup_destination_pgdata , num_threads , !no_sync ,
9921040 exclude_absolute_paths_list , exclude_relative_paths_list );
9931041 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
9941046 return do_restore_or_validate (instanceState , current .backup_id ,
9951047 recovery_target_options ,
9961048 restore_params , no_sync );
@@ -1010,6 +1062,10 @@ main(int argc, char *argv[])
10101062 restore_params ,
10111063 no_sync );
10121064 case SHOW_CMD :
1065+ #ifdef PBCKP_S3
1066+ if (s3_protocol != S3_INVALID_PROTOCOL )
1067+ return do_S3_show (instanceState );
1068+ #endif
10131069 return do_show (catalogState , instanceState , current .backup_id , show_archive );
10141070 case DELETE_CMD :
10151071
@@ -1198,3 +1254,34 @@ opt_exclude_path(ConfigOption *opt, const char *arg)
11981254 else
11991255 opt_parser_add_to_parray_helper (& exclude_relative_paths_list , arg );
12001256}
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