From 9ac9adb2bba29292d039ba4c5021d80f89464f07 Mon Sep 17 00:00:00 2001 From: shaunakv1 Date: Tue, 29 Apr 2025 21:53:00 -0400 Subject: [PATCH 1/2] fixes path issue when reading dumps from s3. fixes https://github.com/databacker/mysql-backup/issues/432 Signed-off-by: shaunakv1 --- pkg/storage/s3/s3.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/storage/s3/s3.go b/pkg/storage/s3/s3.go index ab1c236..fff4049 100644 --- a/pkg/storage/s3/s3.go +++ b/pkg/storage/s3/s3.go @@ -75,6 +75,8 @@ func (s *S3) Pull(ctx context.Context, source, target string, logger *log.Entry) bucket, path := s.url.Hostname(), path.Join(s.url.Path, source) + path = strings.TrimPrefix(path, "/") + // Create a downloader with the session and default options downloader := manager.NewDownloader(client) @@ -86,7 +88,7 @@ func (s *S3) Pull(ctx context.Context, source, target string, logger *log.Entry) defer func() { _ = f.Close() }() // Write the contents of S3 Object to the file - n, err := downloader.Download(context.TODO(), f, &s3.GetObjectInput{ + n, err := downloader.Download(context.TODO(), f, &s3.GetObjectInput{ Bucket: aws.String(bucket), Key: aws.String(path), }) @@ -194,7 +196,7 @@ func (s *S3) getClient(logger *log.Entry) (*s3.Client, error) { // Get the AWS config var configOpts []func(*config.LoadOptions) error // global client options if logger.Level == log.TraceLevel { - configOpts = append(configOpts, config.WithClientLogMode(aws.LogRequestWithBody|aws.LogResponse)) + configOpts = append(configOpts, config.WithClientLogMode(aws.LogRequestWithBody|aws.LogResponse)) } if s.region != "" { configOpts = append(configOpts, config.WithRegion(s.region)) @@ -206,7 +208,7 @@ func (s *S3) getClient(logger *log.Entry) (*s3.Client, error) { "", ))) } - cfg, err := config.LoadDefaultConfig(context.TODO(), + cfg, err := config.LoadDefaultConfig(context.TODO(), configOpts..., ) if err != nil { @@ -215,7 +217,7 @@ func (s *S3) getClient(logger *log.Entry) (*s3.Client, error) { // Get the S3 client var s3opts []func(*s3.Options) // s3 client options - if s.endpoint != "" { + if s.endpoint != "" { cleanEndpoint := getEndpoint(s.endpoint) s3opts = append(s3opts, func(o *s3.Options) { @@ -231,7 +233,7 @@ func (s *S3) getClient(logger *log.Entry) (*s3.Client, error) { ) } - // Create a new S3 service client +// Create a new S3 service client return s3.NewFromConfig(cfg, s3opts...), nil } From 7626f46680a8bec04b97eb461cf3e8bd8250758b Mon Sep 17 00:00:00 2001 From: shaunakv1 Date: Thu, 1 May 2025 21:33:54 -0400 Subject: [PATCH 2/2] formtting fix --- pkg/storage/s3/s3.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/storage/s3/s3.go b/pkg/storage/s3/s3.go index fff4049..f4c9672 100644 --- a/pkg/storage/s3/s3.go +++ b/pkg/storage/s3/s3.go @@ -76,7 +76,7 @@ func (s *S3) Pull(ctx context.Context, source, target string, logger *log.Entry) bucket, path := s.url.Hostname(), path.Join(s.url.Path, source) path = strings.TrimPrefix(path, "/") - + // Create a downloader with the session and default options downloader := manager.NewDownloader(client) @@ -88,7 +88,7 @@ func (s *S3) Pull(ctx context.Context, source, target string, logger *log.Entry) defer func() { _ = f.Close() }() // Write the contents of S3 Object to the file - n, err := downloader.Download(context.TODO(), f, &s3.GetObjectInput{ + n, err := downloader.Download(context.TODO(), f, &s3.GetObjectInput{ Bucket: aws.String(bucket), Key: aws.String(path), }) @@ -196,7 +196,7 @@ func (s *S3) getClient(logger *log.Entry) (*s3.Client, error) { // Get the AWS config var configOpts []func(*config.LoadOptions) error // global client options if logger.Level == log.TraceLevel { - configOpts = append(configOpts, config.WithClientLogMode(aws.LogRequestWithBody|aws.LogResponse)) + configOpts = append(configOpts, config.WithClientLogMode(aws.LogRequestWithBody|aws.LogResponse)) } if s.region != "" { configOpts = append(configOpts, config.WithRegion(s.region)) @@ -208,7 +208,7 @@ func (s *S3) getClient(logger *log.Entry) (*s3.Client, error) { "", ))) } - cfg, err := config.LoadDefaultConfig(context.TODO(), + cfg, err := config.LoadDefaultConfig(context.TODO(), configOpts..., ) if err != nil { @@ -217,7 +217,7 @@ func (s *S3) getClient(logger *log.Entry) (*s3.Client, error) { // Get the S3 client var s3opts []func(*s3.Options) // s3 client options - if s.endpoint != "" { + if s.endpoint != "" { cleanEndpoint := getEndpoint(s.endpoint) s3opts = append(s3opts, func(o *s3.Options) { @@ -233,7 +233,7 @@ func (s *S3) getClient(logger *log.Entry) (*s3.Client, error) { ) } -// Create a new S3 service client + // Create a new S3 service client return s3.NewFromConfig(cfg, s3opts...), nil }