-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (42 loc) · 1.36 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"log"
)
func main() {
config := readConfig()
// Initialize source bucket AWS Session
sourceConfig := &aws.Config{
Region: aws.String(config.Source.Region),
MaxRetries: aws.Int(10),
}
if config.Source.Profile != "" {
sourceConfig.Credentials = credentials.NewSharedCredentials("", config.Source.Profile)
}
sessSource := session.Must(session.NewSession(sourceConfig))
// Initialize destination bucket AWS Session
destConfig := &aws.Config{
Region: aws.String(config.Destination.Region),
MaxRetries: aws.Int(10),
}
if config.Destination.Profile != "" {
destConfig.Credentials = credentials.NewSharedCredentials("", config.Destination.Profile)
}
sessDest := session.Must(session.NewSession(destConfig))
// Setup context and interrupt (ctrl+c) handling
ctx, cancelFunc := context.WithCancel(context.Background())
handleInterrupt(cancelFunc)
// Initialize main copy job
source := NewBucket(config.Source.Bucket, config.Source.Prefix, sessSource, ctx)
dest := NewBucket(config.Destination.Bucket, config.Destination.Prefix, sessDest, ctx)
j := job{
source: source,
destination: dest,
copyChan: make(chan string, config.Parallel),
}
j.Start()
log.Println("All done")
}