Skip to content

Commit 5ba2332

Browse files
dkropachevDmitry Kropachev
authored and
Dmitry Kropachev
committed
add(sctool CLI): add BackupPurge support
1 parent 0eb3765 commit 5ba2332

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

pkg/cmd/sctool/sctool.go

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/scylladb/scylla-manager/v3/pkg/command/backup"
1111
"github.com/scylladb/scylla-manager/v3/pkg/command/backup/backupdelete"
1212
"github.com/scylladb/scylla-manager/v3/pkg/command/backup/backuplist"
13+
"github.com/scylladb/scylla-manager/v3/pkg/command/backup/backuppurge"
1314
"github.com/scylladb/scylla-manager/v3/pkg/command/backup/backupvalidate"
1415
"github.com/scylladb/scylla-manager/v3/pkg/command/cluster/clusteradd"
1516
"github.com/scylladb/scylla-manager/v3/pkg/command/cluster/clusterdelete"
@@ -56,6 +57,7 @@ func buildCommand() *cobra.Command {
5657

5758
backupCmd := backup.NewCommand(&client)
5859
backupCmd.AddCommand(
60+
backuppurge.NewCommand(&client),
5961
backupdelete.NewCommand(&client),
6062
backupfiles.NewCommand(&client),
6163
backuplist.NewCommand(&client),

pkg/command/backup/backuppurge/cmd.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (C) 2017 ScyllaDB
2+
3+
package backuppurge
4+
5+
import (
6+
_ "embed"
7+
"fmt"
8+
"time"
9+
10+
"github.com/spf13/cobra"
11+
"go.uber.org/atomic"
12+
"gopkg.in/yaml.v2"
13+
14+
"github.com/scylladb/scylla-manager/v3/pkg/command/flag"
15+
"github.com/scylladb/scylla-manager/v3/pkg/managerclient"
16+
)
17+
18+
//go:embed res.yaml
19+
var res []byte
20+
21+
type command struct {
22+
cobra.Command
23+
client *managerclient.Client
24+
dryRun bool
25+
cluster string
26+
location []string
27+
}
28+
29+
func NewCommand(client *managerclient.Client) *cobra.Command {
30+
cmd := &command{
31+
client: client,
32+
}
33+
if err := yaml.Unmarshal(res, &cmd.Command); err != nil {
34+
panic(err)
35+
}
36+
37+
defer flag.MustSetUsages(&cmd.Command, res, "cluster")
38+
cmd.init()
39+
cmd.RunE = func(_ *cobra.Command, args []string) error {
40+
return cmd.run()
41+
}
42+
return &cmd.Command
43+
}
44+
45+
func (cmd *command) init() {
46+
w := flag.Wrap(cmd.Flags())
47+
w.Cluster(&cmd.cluster)
48+
w.Location(&cmd.location)
49+
w.DryRun(&cmd.dryRun)
50+
}
51+
52+
func (cmd *command) run() error {
53+
stillWaiting := atomic.NewBool(true)
54+
time.AfterFunc(5*time.Second, func() {
55+
if stillWaiting.Load() {
56+
fmt.Fprintf(cmd.OutOrStderr(), "NOTICE: this may take a while, we are reading metadata from backup location(s)\n")
57+
}
58+
})
59+
resp, err := cmd.client.PurgeBackups(cmd.Context(), cmd.cluster, cmd.location, cmd.dryRun)
60+
if err != nil {
61+
return err
62+
}
63+
return resp.Render(cmd.OutOrStdout())
64+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use: purge --cluster <id|name> [--location [<dc>:]<provider>:<bucket>] [--dry-run] [flags]
2+
3+
short: Purge backup files in remote locations
4+
5+
long: |
6+
Purge stale backup data and meta files in remote locations for provided cluster.
7+
That is data and files of:
8+
- temporary manifests,
9+
- manifests over task days retention days policy,
10+
- manifests over task retention policy,
11+
- manifests of deleted tasks.
12+
It`s return information from manifests of deleted files.
13+
14+
location: |
15+
If no location provided - locations gets from all tasks

pkg/command/flag/flag.go

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ func (w Wrapper) Location(p *[]string) {
115115
w.fs.StringSliceVarP(p, "location", "L", nil, usage["location"])
116116
}
117117

118+
func (w Wrapper) DryRun(p *bool) {
119+
w.fs.BoolVarP(p, "dry-run", "d", false, usage["dry-run"])
120+
}
121+
118122
//
119123
// Task schedule flags
120124
//

pkg/command/flag/usage.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ dc: |
1919
fail-fast: |
2020
Stops the task run on the first error.
2121
22+
dry-run: |
23+
In dry-run mode no any changes will be done, result be returned like with changes.
24+
2225
keyspace: |
2326
A list of `glob` patterns separated by a comma used to include or exclude tables.
2427
The patterns match keyspaces and tables, separate the keyspace name from the table name with a dot e.g. ``keyspace,!keyspace.table_prefix_*``.

0 commit comments

Comments
 (0)