forked from Balraj3/golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_with_routine.go
50 lines (40 loc) · 1.1 KB
/
copy_with_routine.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
package main
import (
"flag"
"fmt"
"net/url"
"sync"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
func main() {
profile := flag.String("p", "defualt", "Mentoin profile")
source_buc := flag.String("s", "", "Enter source bucket name")
dest_buc := flag.String("d", "", "Enter destination bucket name")
flag.Parse()
sess, err := session.NewSessionWithOptions(session.Options{
Profile: *profile,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
fmt.Print("error")
}
svc := s3.New(sess)
//get s3 items to resp
resp, err := svc.ListObjectsV2(&s3.ListObjectsV2Input{Bucket: aws.String(*source_buc)})
var wg sync.WaitGroup
wg.Add(int(*resp.KeyCount))
for _, item := range resp.Contents {
go func() {
defer wg.Done()
ob1 := *source_buc + "/" + (*item.Key)
//fmt.Println(ob1)
_, err = svc.CopyObject(&s3.CopyObjectInput{Bucket: aws.String(*dest_buc),
CopySource: aws.String(url.PathEscape(ob1)), Key: aws.String(*item.Key)})
}()
time.Sleep(5 * time.Millisecond)
}
wg.Wait()
}