|
9 | 9 | "errors"
|
10 | 10 | "fmt"
|
11 | 11 | "os"
|
| 12 | + "os/exec" |
12 | 13 | "path/filepath"
|
13 | 14 | "strings"
|
14 | 15 |
|
@@ -289,33 +290,39 @@ func (s3st *s3Storage) DownloadSnapshot(ctx context.Context, destination string,
|
289 | 290 | return s3st.download(ctx, destination, name, mappings)
|
290 | 291 | }
|
291 | 292 |
|
| 293 | +// download object using s5cmd (prior to which we used aws sdk) |
292 | 294 | func (s3st *s3Storage) download(ctx context.Context, destination string, obj string, mappings []archive.IDMapping) (found bool, err error) {
|
293 |
| - downloader := s3manager.NewDownloader(s3st.client, func(d *s3manager.Downloader) { |
294 |
| - d.Concurrency = defaultCopyConcurrency |
295 |
| - d.PartSize = defaultPartSize * megabytes |
296 |
| - d.BufferProvider = s3manager.NewPooledBufferedWriterReadFromProvider(25 * megabytes) |
297 |
| - }) |
298 |
| - |
299 |
| - s3File, err := os.CreateTemp("", "temporal-s3-file") |
| 295 | + tempFile, err := os.CreateTemp("", "temporal-s3-file") |
300 | 296 | if err != nil {
|
301 | 297 | return true, xerrors.Errorf("creating temporal file: %s", err.Error())
|
302 | 298 | }
|
303 |
| - defer os.Remove(s3File.Name()) |
304 |
| - |
305 |
| - _, err = downloader.Download(ctx, s3File, &s3.GetObjectInput{ |
306 |
| - Bucket: aws.String(s3st.Config.Bucket), |
307 |
| - Key: aws.String(obj), |
308 |
| - }) |
| 299 | + tempFile.Close() |
| 300 | + |
| 301 | + args := []string{ |
| 302 | + "cp", |
| 303 | + // # of file parts to download at once |
| 304 | + "--concurrency", "20", |
| 305 | + // size in MB of each part |
| 306 | + "--part-size", "25", |
| 307 | + destination, |
| 308 | + tempFile.Name(), |
| 309 | + } |
| 310 | + cmd := exec.Command("s5cmd", args...) |
| 311 | + out, err := cmd.CombinedOutput() |
309 | 312 | if err != nil {
|
310 |
| - return false, err |
| 313 | + log.WithError(err).WithField("out", string(out)).Error("unexpected error downloading file") |
| 314 | + return true, xerrors.Errorf("unexpected error downloading file") |
311 | 315 | }
|
312 | 316 |
|
313 |
| - _, err = s3File.Seek(0, 0) |
| 317 | + tempFile, err = os.Open(tempFile.Name()) |
314 | 318 | if err != nil {
|
315 |
| - return false, err |
| 319 | + return true, xerrors.Errorf("unexpected error opening downloaded file") |
316 | 320 | }
|
317 | 321 |
|
318 |
| - err = archive.ExtractTarbal(ctx, s3File, destination, archive.WithUIDMapping(mappings), archive.WithGIDMapping(mappings)) |
| 322 | + defer os.Remove(tempFile.Name()) |
| 323 | + defer tempFile.Close() |
| 324 | + |
| 325 | + err = archive.ExtractTarbal(ctx, tempFile, destination, archive.WithUIDMapping(mappings), archive.WithGIDMapping(mappings)) |
319 | 326 | if err != nil {
|
320 | 327 | return true, xerrors.Errorf("tar %s: %s", destination, err.Error())
|
321 | 328 | }
|
|
0 commit comments