@@ -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 */
@@ -952,6 +967,19 @@ main(int argc, char *argv[])
952967
953968 compress_init (backup_subcmd );
954969
970+ #ifdef PBCKP_S3
971+ if (s3_protocol != S3_INVALID_PROTOCOL )
972+ {
973+ char * s3_config_file = "" ;
974+ read_s3_config (s3_config_file );
975+ }
976+ else
977+ {
978+ if (s3_target_bucket != NULL )
979+ elog (WARNING , "You cannot specify s3-target without using --s3 option with name of protocol" );
980+ }
981+ #endif
982+
955983 /* do actual operation */
956984 switch (backup_subcmd )
957985 {
@@ -964,11 +992,27 @@ main(int argc, char *argv[])
964992 wal_file_path , wal_file_name , batch_size , !no_validate_wal );
965993 break ;
966994 case ADD_INSTANCE_CMD :
967- return do_add_instance (instanceState , & instance_config );
995+ {
996+ int err = 0 ;
997+ err = do_add_instance (instanceState , & instance_config );
998+ #ifdef PBCKP_S3
999+ if (err == 0 && s3_protocol != S3_INVALID_PROTOCOL )
1000+ err = do_S3_write_config (& instance_config );
1001+ #endif
1002+ return err ;
1003+ }
9681004 case DELETE_INSTANCE_CMD :
9691005 return do_delete_instance (instanceState );
9701006 case INIT_CMD :
971- return do_init (catalogState );
1007+ {
1008+ int err = 0 ;
1009+ err = do_init (catalogState );
1010+ #ifdef PBCKP_S3
1011+ if (err == 0 && s3_protocol != S3_INVALID_PROTOCOL )
1012+ err = S3_pre_start_check (config );
1013+ #endif
1014+ return err ;
1015+ }
9721016 case BACKUP_CMD :
9731017 {
9741018 current .stream = stream_wal ;
@@ -983,13 +1027,21 @@ main(int argc, char *argv[])
9831027 elog (ERROR , "required parameter not specified: BACKUP_MODE "
9841028 "(-b, --backup-mode)" );
9851029
1030+ #ifdef PBCKP_S3
1031+ if (s3_protocol != S3_INVALID_PROTOCOL )
1032+ return do_S3_backup (instanceState , set_backup_params , start_time );
1033+ #endif
9861034 return do_backup (instanceState , set_backup_params ,
9871035 no_validate , no_sync , backup_logs , start_time );
9881036 }
9891037 case CATCHUP_CMD :
9901038 return do_catchup (catchup_source_pgdata , catchup_destination_pgdata , num_threads , !no_sync ,
9911039 exclude_absolute_paths_list , exclude_relative_paths_list );
9921040 case RESTORE_CMD :
1041+ #ifdef PBCKP_S3
1042+ if (s3_protocol != S3_INVALID_PROTOCOL )
1043+ return do_S3_restore (instanceState , current .backup_id );
1044+ #endif
9931045 return do_restore_or_validate (instanceState , current .backup_id ,
9941046 recovery_target_options ,
9951047 restore_params , no_sync );
@@ -1009,6 +1061,10 @@ main(int argc, char *argv[])
10091061 restore_params ,
10101062 no_sync );
10111063 case SHOW_CMD :
1064+ #ifdef PBCKP_S3
1065+ if (s3_protocol != S3_INVALID_PROTOCOL )
1066+ return do_S3_show (instanceState );
1067+ #endif
10121068 return do_show (catalogState , instanceState , current .backup_id , show_archive );
10131069 case DELETE_CMD :
10141070
@@ -1197,3 +1253,34 @@ opt_exclude_path(ConfigOption *opt, const char *arg)
11971253 else
11981254 opt_parser_add_to_parray_helper (& exclude_relative_paths_list , arg );
11991255}
1256+
1257+ #ifdef PBCKP_S3
1258+ static S3_protocol
1259+ parse_s3_protocol (const char * value )
1260+ {
1261+ const char * v = value ;
1262+ size_t len ;
1263+
1264+ /* Skip all spaces detected */
1265+ while (IsSpace (* v ))
1266+ v ++ ;
1267+ len = strlen (v );
1268+
1269+ if (len > 0 && pg_strncasecmp ("MINIO" , v , len ) == 0 )
1270+ return S3_MINIO_PROTOCOL ;
1271+ if (len > 0 && pg_strncasecmp ("AWS" , v , len ) == 0 )
1272+ return S3_AWS_PROTOCOL ;
1273+ else if (len > 0 && pg_strncasecmp ("GOOGLE" , v , len ) == 0 )
1274+ return S3_GOOGLE_PROTOCOL ;
1275+ else if (len > 0 && pg_strncasecmp ("VK" , v , len ) == 0 )
1276+ return S3_VK_PROTOCOL ;
1277+ else
1278+ return S3_INVALID_PROTOCOL ;
1279+ }
1280+
1281+ static void
1282+ opt_s3_protocol (ConfigOption * opt , const char * arg )
1283+ {
1284+ s3_protocol = parse_s3_protocol (arg );
1285+ }
1286+ #endif
0 commit comments