This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive.go
104 lines (101 loc) · 3.12 KB
/
archive.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package cmd
import (
"github.com/SEEK-Jobs/dynamotools/archive"
"github.com/urfave/cli"
)
// BuildArchive builds the cli command for archive funationality
func BuildArchive() cli.Command {
return cli.Command{
Name: "archive",
Usage: `region [aws region name] table [dynamo table name] tableindex [index to use for scanning]
partitions [scan partitions for parallel scanning] limit [limit for scanning no of records]
bucket [s3 bucket name] chunksize [chunk sizes (in MB) to be uploaded to the bucket]
concurrency [concurrency for uploads to the bucket]`,
Description: "archive scans the [table] using the specified [tableindex] and saves it the s3 [bucket]",
Flags: []cli.Flag{
cli.StringFlag{
Name: "region, r",
Value: "ap-southeast-2",
Usage: "aws region name where your dynamodb table and s3 bucket is",
},
cli.StringFlag{
Name: "table, t",
Usage: "dynamodb table name",
},
cli.StringFlag{
Name: "tableindex, i",
Usage: "index for scanning the dynamo table",
},
cli.IntFlag{
Name: "partitions, p",
Value: 1,
Usage: "partitions for parallel scanning",
},
cli.IntFlag{
Name: "limit, l",
Value: 100,
Usage: "limit for scanning records",
},
cli.StringFlag{
Name: "filtername, fn",
Usage: "name of the scan filter attribute",
},
cli.StringFlag{
Name: "filtertype, ft",
Usage: "type of the scan filter attribute (string|number)",
},
cli.StringFlag{
Name: "filteroperator, fo",
Usage: "operator for the scan filter ( < | = | > )",
},
cli.StringFlag{
Name: "filtervalue, fv",
Usage: "value for the scan filter",
},
cli.StringFlag{
Name: "bucket, b",
Usage: "name of the bucket to store the archived data",
},
cli.Int64Flag{
Name: "chunksize, cs",
Value: 16,
Usage: "chunk sizes (in MB) to be uploaded to the bucket",
},
cli.Int64Flag{
Name: "concurrency, uc",
Value: 10,
Usage: "concurrency for uploads to the bucket",
},
cli.StringFlag{
Name: "prefix, pf",
Usage: "folder where archived data will be stored (optional)",
},
},
SkipFlagParsing: false,
Before: func(c *cli.Context) error {
if c.String("table") == "" && c.String("t") == "" {
return cli.NewExitError("missing value for [table]", 86)
} else if c.String("bucket") == "" && c.String("b") == "" {
return cli.NewExitError("missing value for [bucket]", 86)
}
return nil
},
Action: func(c *cli.Context) error {
return archive.ToS3(&archive.S3ArchiveConfig{
Region: c.String("region"),
TableName: c.String("table"),
TableIndex: c.String("tableindex"),
ScanPartitions: c.Int("partitions"),
ScanLimit: c.Int("limit"),
ScanFilterName: c.String("filtername"),
ScanFilterType: c.String("filtertype"),
ScanFilterOpertor: c.String("filteroperator"),
ScanFilterValue: c.String("filtervalue"),
UploadBucket: c.String("bucket"),
UploadChunkSize: c.Int64("chunksize"),
UploadConcurrency: c.Int("concurrency"),
BackupPrefix: c.String("prefix"),
})
},
}
}