-
Notifications
You must be signed in to change notification settings - Fork 10
/
cmd_delete.go
78 lines (62 loc) · 1.69 KB
/
cmd_delete.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2016 Gareth Watts
// Licensed under an MIT license
// See the LICENSE file for details
package main
import (
"errors"
"fmt"
"io"
"github.com/Bowery/prompt"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/gwatts/dyndump/dyndump"
"gopkg.in/cheggaaa/pb.v1"
)
type deleter struct {
del *dyndump.S3Deleter
// options
force *bool
s3BucketName *string
s3Prefix *string
}
func (d *deleter) init() error {
del, err := dyndump.NewS3Deleter(s3.New(session.New()), *d.s3BucketName, *d.s3Prefix)
if err != nil {
return err
}
if !*d.force {
fmt.Printf("Delete backup of table %s from s3://%s/%s\n\n", del.Metadata().TableName, *d.s3BucketName, *d.s3Prefix)
ok, err := prompt.Ask("Are you sure you wish to delete the above backup")
if err != nil {
return fmt.Errorf("Could not prompt for confirmation (use --force to override): %v", err)
}
if !ok {
return errors.New("User rejected delete")
}
}
d.del = del
return nil
}
func (d *deleter) start(infoWriter io.Writer) (done chan error, err error) {
fmt.Fprintf(infoWriter, "Beginning s3 delete prefix=s3://%s/%s parts=%d\n",
*d.s3BucketName, *d.s3Prefix, d.del.Metadata().PartCount)
done = make(chan error)
go func() {
done <- d.del.Delete()
}()
return done, nil
}
func (d *deleter) newProgressBar() *pb.ProgressBar {
bar := pb.New64(d.del.Metadata().PartCount)
return bar
}
func (d *deleter) updateProgress(bar *pb.ProgressBar) {
bar.Set64(d.del.Completed())
}
func (d *deleter) abort() {
d.del.Abort()
}
func (d *deleter) printFinalStats(w io.Writer) {
fmt.Fprintf(w, "Deleted %d parts from s3://%s/%s\n",
d.del.Completed(), *d.s3BucketName, *d.s3Prefix)
}