diff --git a/cmd/auto-complete.go b/cmd/auto-complete.go
index abf95870..686dba02 100644
--- a/cmd/auto-complete.go
+++ b/cmd/auto-complete.go
@@ -266,14 +266,15 @@ var completeCmds = map[string]complete.Predictor{
"/encrypt/info": s3Complete{deepLevel: 2},
"/encrypt/clear": s3Complete{deepLevel: 2},
- "/replicate/add": s3Complete{deepLevel: 2},
- "/replicate/edit": s3Complete{deepLevel: 2},
- "/replicate/ls": s3Complete{deepLevel: 2},
- "/replicate/rm": s3Complete{deepLevel: 2},
- "/replicate/export": s3Complete{deepLevel: 2},
- "/replicate/import": s3Complete{deepLevel: 2},
- "/replicate/status": s3Complete{deepLevel: 2},
- "/replicate/resync": s3Complete{deepLevel: 2},
+ "/replicate/add": s3Complete{deepLevel: 2},
+ "/replicate/edit": s3Complete{deepLevel: 2},
+ "/replicate/ls": s3Complete{deepLevel: 2},
+ "/replicate/rm": s3Complete{deepLevel: 2},
+ "/replicate/export": s3Complete{deepLevel: 2},
+ "/replicate/import": s3Complete{deepLevel: 2},
+ "/replicate/status": s3Complete{deepLevel: 2},
+ "/replicate/resync/start": s3Complete{deepLevel: 3},
+ "/replicate/resync/status": s3Complete{deepLevel: 3},
"/tag/list": s3Completer,
"/tag/remove": s3Completer,
diff --git a/cmd/client-fs.go b/cmd/client-fs.go
index 40ac8a03..da226dd2 100644
--- a/cmd/client-fs.go
+++ b/cmd/client-fs.go
@@ -1233,6 +1233,14 @@ func (f *fsClient) ResetReplication(ctx context.Context, before time.Duration, a
})
}
+// ReplicationResyncStatus - gets status of replication resync for this target arn
+func (f *fsClient) ReplicationResyncStatus(ctx context.Context, arn string) (rinfo replication.ResyncTargetsInfo, err *probe.Error) {
+ return rinfo, probe.NewError(APINotImplemented{
+ API: "ReplicationResyncStatus",
+ APIType: "filesystem",
+ })
+}
+
// Get encryption info for a bucket, not implemented.
func (f *fsClient) GetEncryption(ctx context.Context) (string, string, *probe.Error) {
return "", "", probe.NewError(APINotImplemented{
diff --git a/cmd/client-s3.go b/cmd/client-s3.go
index 6bbdafdd..b0fa2338 100644
--- a/cmd/client-s3.go
+++ b/cmd/client-s3.go
@@ -2587,6 +2587,20 @@ func (c *S3Client) ResetReplication(ctx context.Context, before time.Duration, t
return rinfo, nil
}
+// ReplicationResyncStatus - gets status of replication resync for this target arn
+func (c *S3Client) ReplicationResyncStatus(ctx context.Context, arn string) (rinfo replication.ResyncTargetsInfo, err *probe.Error) {
+ bucket, _ := c.url2BucketAndObject()
+ if bucket == "" {
+ return rinfo, probe.NewError(BucketNameEmpty{})
+ }
+
+ rinfo, e := c.api.GetBucketReplicationResyncStatus(ctx, bucket, arn)
+ if e != nil {
+ return rinfo, probe.NewError(e)
+ }
+ return rinfo, nil
+}
+
// GetEncryption - gets bucket encryption info.
func (c *S3Client) GetEncryption(ctx context.Context) (algorithm, keyID string, err *probe.Error) {
bucket, _ := c.url2BucketAndObject()
diff --git a/cmd/client.go b/cmd/client.go
index 9800a85e..1d1ebb07 100644
--- a/cmd/client.go
+++ b/cmd/client.go
@@ -158,6 +158,8 @@ type Client interface {
RemoveReplication(ctx context.Context) *probe.Error
GetReplicationMetrics(ctx context.Context) (replication.Metrics, *probe.Error)
ResetReplication(ctx context.Context, before time.Duration, arn string) (replication.ResyncTargetsInfo, *probe.Error)
+ ReplicationResyncStatus(ctx context.Context, arn string) (rinfo replication.ResyncTargetsInfo, err *probe.Error)
+
// Encryption operations
GetEncryption(ctx context.Context) (string, string, *probe.Error)
SetEncryption(ctx context.Context, algorithm, kmsKeyID string) *probe.Error
diff --git a/cmd/replicate-main.go b/cmd/replicate-main.go
index f4ae0bb1..e0851862 100644
--- a/cmd/replicate-main.go
+++ b/cmd/replicate-main.go
@@ -24,7 +24,7 @@ var replicateSubcommands = []cli.Command{
replicateEditCmd,
replicateListCmd,
replicateStatusCmd,
- replicateResetCmd,
+ replicateResyncCmd,
replicateExportCmd,
replicateImportCmd,
replicateRemoveCmd,
diff --git a/cmd/replicate-reset-main.go b/cmd/replicate-reset-main.go
new file mode 100644
index 00000000..8c66b8eb
--- /dev/null
+++ b/cmd/replicate-reset-main.go
@@ -0,0 +1,43 @@
+// Copyright (c) 2015-2022 MinIO, Inc.
+//
+// This file is part of MinIO Object Storage stack
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+package cmd
+
+import "github.com/minio/cli"
+
+var replicateResyncSubcommands = []cli.Command{
+ replicateResyncStartCmd,
+ replicateResyncStatusCmd,
+}
+
+var replicateResyncCmd = cli.Command{
+ Name: "resync",
+ Usage: "replicate back all previously replicated objects",
+ HideHelpCommand: true,
+ Action: mainReplicateResync,
+ Before: setGlobalsFromContext,
+ Flags: globalFlags,
+ Subcommands: replicateResyncSubcommands,
+ Aliases: []string{"reset"},
+}
+
+// mainReplicateResync is the handle for "mc replicate resync" command.
+func mainReplicateResync(ctx *cli.Context) error {
+ commandNotFound(ctx, replicateResyncSubcommands)
+ return nil
+ // Sub-commands like "status", "start", have their own main.
+}
diff --git a/cmd/replicate-reset.go b/cmd/replicate-reset-start.go
similarity index 72%
rename from cmd/replicate-reset.go
rename to cmd/replicate-reset-start.go
index 1b9e36d0..a5b73ac7 100644
--- a/cmd/replicate-reset.go
+++ b/cmd/replicate-reset-start.go
@@ -32,10 +32,10 @@ import (
"maze.io/x/duration"
)
-var replicateResetFlags = []cli.Flag{
+var replicateResyncStartFlags = []cli.Flag{
cli.StringFlag{
Name: "older-than",
- Usage: "re-replicate objects older than n days",
+ Usage: "replicate back objects older than n days",
},
cli.StringFlag{
Name: "remote-bucket",
@@ -43,14 +43,13 @@ var replicateResetFlags = []cli.Flag{
},
}
-var replicateResetCmd = cli.Command{
- Name: "resync",
- Usage: "re-replicate all previously replicated objects",
- Aliases: []string{"reset"},
- Action: mainReplicateReset,
+var replicateResyncStartCmd = cli.Command{
+ Name: "start",
+ Usage: "start replicating back all previously replicated objects",
+ Action: mainReplicateResyncStart,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
- Flags: append(globalFlags, replicateResetFlags...),
+ Flags: append(globalFlags, replicateResyncStartFlags...),
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
@@ -69,17 +68,17 @@ EXAMPLES:
`,
}
-// checkReplicateResetSyntax - validate all the passed arguments
-func checkReplicateResetSyntax(ctx *cli.Context) {
+// checkReplicateResyncStartSyntax - validate all the passed arguments
+func checkReplicateResyncStartSyntax(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
- cli.ShowCommandHelpAndExit(ctx, "reset", 1) // last argument is exit code
+ cli.ShowCommandHelpAndExit(ctx, "start", 1) // last argument is exit code
}
if ctx.String("remote-bucket") == "" {
fatal(errDummy().Trace(), "--remote-bucket flag needs to be specified.")
}
}
-type replicateResetMessage struct {
+type replicateResyncMessage struct {
Op string `json:"op"`
URL string `json:"url"`
ResyncTargetsInfo replication.ResyncTargetsInfo `json:"resyncInfo"`
@@ -87,27 +86,27 @@ type replicateResetMessage struct {
TargetArn string `json:"targetArn"`
}
-func (r replicateResetMessage) JSON() string {
+func (r replicateResyncMessage) JSON() string {
r.Status = "success"
jsonMessageBytes, e := json.MarshalIndent(r, "", " ")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
return string(jsonMessageBytes)
}
-func (r replicateResetMessage) String() string {
+func (r replicateResyncMessage) String() string {
if len(r.ResyncTargetsInfo.Targets) == 1 {
- return console.Colorize("replicateResetMessage", fmt.Sprintf("Replication reset started for %s with ID %s", r.URL, r.ResyncTargetsInfo.Targets[0].ResetID))
+ return console.Colorize("replicateResyncMessage", fmt.Sprintf("Replication reset started for %s with ID %s", r.URL, r.ResyncTargetsInfo.Targets[0].ResetID))
}
- return console.Colorize("replicateResetMessage", fmt.Sprintf("Replication reset started for %s", r.URL))
+ return console.Colorize("replicateResyncMessage", fmt.Sprintf("Replication reset started for %s", r.URL))
}
-func mainReplicateReset(cliCtx *cli.Context) error {
- ctx, cancelReplicateReset := context.WithCancel(globalContext)
- defer cancelReplicateReset()
+func mainReplicateResyncStart(cliCtx *cli.Context) error {
+ ctx, cancelReplicateResyncStart := context.WithCancel(globalContext)
+ defer cancelReplicateResyncStart()
- console.SetColor("replicateResetMessage", color.New(color.FgGreen))
+ console.SetColor("replicateResyncMessage", color.New(color.FgGreen))
- checkReplicateResetSyntax(cliCtx)
+ checkReplicateResyncStartSyntax(cliCtx)
// Get the alias parameter from cli
args := cliCtx.Args()
@@ -133,8 +132,8 @@ func mainReplicateReset(cliCtx *cli.Context) error {
rinfo, err := client.ResetReplication(ctx, olderThan, cliCtx.String("remote-bucket"))
fatalIf(err.Trace(args...), "Unable to reset replication")
- printMsg(replicateResetMessage{
- Op: "status",
+ printMsg(replicateResyncMessage{
+ Op: "start",
URL: aliasedURL,
ResyncTargetsInfo: rinfo,
})
diff --git a/cmd/replicate-reset-status.go b/cmd/replicate-reset-status.go
new file mode 100644
index 00000000..1a12a7af
--- /dev/null
+++ b/cmd/replicate-reset-status.go
@@ -0,0 +1,161 @@
+// Copyright (c) 2015-2022 MinIO, Inc.
+//
+// This file is part of MinIO Object Storage stack
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+package cmd
+
+import (
+ "context"
+ "fmt"
+
+ humanize "github.com/dustin/go-humanize"
+ "github.com/fatih/color"
+ "github.com/minio/cli"
+ json "github.com/minio/colorjson"
+ "github.com/minio/mc/pkg/probe"
+ "github.com/minio/minio-go/v7/pkg/replication"
+ "github.com/minio/pkg/console"
+)
+
+var replicateResyncStatusFlags = []cli.Flag{
+ cli.StringFlag{
+ Name: "remote-bucket",
+ Usage: "remote bucket ARN",
+ },
+}
+
+var replicateResyncStatusCmd = cli.Command{
+ Name: "status",
+ Usage: "status of replication recovery",
+ Action: mainreplicateResyncStatus,
+ OnUsageError: onUsageError,
+ Before: setGlobalsFromContext,
+ Flags: append(globalFlags, replicateResyncStatusFlags...),
+ CustomHelpTemplate: `NAME:
+ {{.HelpName}} - {{.Usage}}
+
+USAGE:
+ {{.HelpName}} TARGET
+
+FLAGS:
+ {{range .VisibleFlags}}{{.}}
+ {{end}}
+EXAMPLES:
+ 1. Status of replication resync in bucket "mybucket" under alias "myminio" for all targets.
+ {{.Prompt}} {{.HelpName}} myminio/mybucket
+
+ 2. Status of replication resync in bucket "mybucket" under specific remote bucket target.
+ {{.Prompt}} {{.HelpName}} myminio/mybucket --remote-bucket "arn:minio:replication::xxx:mybucket"
+`,
+}
+
+// checkreplicateResyncStatusSyntax - validate all the passed arguments
+func checkreplicateResyncStatusSyntax(ctx *cli.Context) {
+ if len(ctx.Args()) != 1 {
+ cli.ShowCommandHelpAndExit(ctx, "status", 1) // last argument is exit code
+ }
+}
+
+type replicateResyncStatusMessage struct {
+ Op string `json:"op"`
+ URL string `json:"url"`
+ ResyncTargetsInfo replication.ResyncTargetsInfo `json:"resyncInfo"`
+ Status string `json:"status"`
+ TargetArn string `json:"targetArn"`
+}
+
+func (r replicateResyncStatusMessage) JSON() string {
+ r.Status = "success"
+ jsonMessageBytes, e := json.MarshalIndent(r, "", " ")
+ fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
+ return string(jsonMessageBytes)
+}
+
+func (r replicateResyncStatusMessage) String() string {
+ if len(r.ResyncTargetsInfo.Targets) == 0 {
+ return console.Colorize("replicateResyncStatusWarn", "No replication resync status available.")
+ }
+ coloredDot := console.Colorize("Headers", dot)
+ var rows string
+ rows += console.Colorize("TDetail", "Resync status summary:")
+
+ for _, st := range r.ResyncTargetsInfo.Targets {
+ rows += "\n"
+ rows += console.Colorize("replicateResyncStatusMsg", newPrettyTable(" | ",
+ Field{"ARN", 120},
+ ).buildRow(fmt.Sprintf("%s %s", coloredDot, st.Arn)))
+ rows += "\n"
+ rows += console.Colorize("TDetail", " Status: ")
+ rows += console.Colorize(st.ResyncStatus, st.ResyncStatus)
+ rows += "\n"
+
+ maxLen := 15
+ theme := []string{"Replicated", "Failed"}
+ rows += console.Colorize("THeaders", newPrettyTable(" | ",
+ Field{"Status", 21},
+ Field{"Size", maxLen},
+ Field{"Count", maxLen},
+ ).buildRow(" Replication Status", "Size (Bytes)", "Count"))
+ rows += "\n"
+ rows += console.Colorize(theme[0], newPrettyTable(" | ",
+ Field{"Status", 21},
+ Field{"Size", maxLen},
+ Field{"Count", maxLen},
+ ).buildRow(" Replicated", humanize.IBytes(uint64(st.ReplicatedSize)), humanize.Comma(int64(st.ReplicatedCount))))
+ rows += "\n"
+ rows += console.Colorize(theme[0], newPrettyTable(" | ",
+ Field{"Status", 21},
+ Field{"Size", maxLen},
+ Field{"Count", maxLen},
+ ).buildRow(" Failed", humanize.IBytes(uint64(st.FailedSize)), humanize.Comma(int64(st.FailedCount))))
+ rows += "\n"
+ }
+ return rows
+}
+
+func mainreplicateResyncStatus(cliCtx *cli.Context) error {
+ ctx, cancelreplicateResyncStatus := context.WithCancel(globalContext)
+ defer cancelreplicateResyncStatus()
+
+ console.SetColor("replicateResyncStatusWarn", color.New(color.FgHiYellow))
+ console.SetColor("replicateResyncStatusMsg", color.New(color.FgGreen))
+ console.SetColor("Headers", color.New(color.FgGreen, color.Bold))
+ console.SetColor("THeaders", color.New(color.Bold, color.FgCyan))
+
+ console.SetColor("TDetail", color.New(color.FgWhite, color.Bold))
+ console.SetColor("Ongoing", color.New(color.Bold, color.FgYellow))
+ console.SetColor("Failed", color.New(color.Bold, color.FgRed))
+ console.SetColor("Completed", color.New(color.Bold, color.FgGreen))
+
+ checkreplicateResyncStatusSyntax(cliCtx)
+
+ // Get the alias parameter from cli
+ args := cliCtx.Args()
+ aliasedURL := args.Get(0)
+ // Create a new Client
+ client, err := newClient(aliasedURL)
+ fatalIf(err, "Unable to initialize connection.")
+
+ rinfo, err := client.ReplicationResyncStatus(ctx, cliCtx.String("remote-bucket"))
+ fatalIf(err.Trace(args...), "Unable to get replication resync status")
+ printMsg(replicateResyncStatusMessage{
+ Op: "status",
+ URL: aliasedURL,
+ ResyncTargetsInfo: rinfo,
+ TargetArn: cliCtx.String("remote-bucket"),
+ })
+ return nil
+}
diff --git a/docs/minio-client-complete-guide.md b/docs/minio-client-complete-guide.md
index 8381d53e..c8beab42 100644
--- a/docs/minio-client-complete-guide.md
+++ b/docs/minio-client-complete-guide.md
@@ -1897,8 +1897,14 @@ mc replicate export myminio/mybucket > /data/replicate/config
mc replicate status myminio/mybucket
```
-*Example: Resync replication of previously replicated objects from `mybucket` on alias `myminio` to configured remote target in replication configuration.
+*Example: Resync replication of previously replicated objects from `mybucket` on alias `myminio` to remote target "arn:minio:replication::xxx:mybucket".
```
-mc replicate resync myminio/mybucket
+mc replicate resync start myminio/mybucket --remote-bucket "arn:minio:replication::xxx:mybucket"
+```
+
+*Example: Show status of replication resync of target "arn:minio:replication::xxx:mybucket" for `mybucket` on alias `myminio`.
+
+```
+mc replicate resync status myminio/mybucket --remote-bucket "arn:minio:replication::xxx:mybucket"
```
diff --git a/go.mod b/go.mod
index 46cdc4c3..3e1b575d 100644
--- a/go.mod
+++ b/go.mod
@@ -20,7 +20,7 @@ require (
github.com/minio/filepath v1.0.0
github.com/minio/madmin-go v1.3.1
github.com/minio/md5-simd v1.1.2 // indirect
- github.com/minio/minio-go/v7 v7.0.21
+ github.com/minio/minio-go/v7 v7.0.22-0.20220210201649-8c600e5ae0e8
github.com/minio/pkg v1.1.14
github.com/minio/selfupdate v0.4.0
github.com/minio/sha256-simd v1.0.0
diff --git a/go.sum b/go.sum
index 28598696..e31f23ae 100644
--- a/go.sum
+++ b/go.sum
@@ -292,8 +292,8 @@ github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77Z
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
github.com/minio/minio-go/v7 v7.0.11-0.20210302210017-6ae69c73ce78/go.mod h1:mTh2uJuAbEqdhMVl6CMIIZLUeiMiWtJR4JB8/5g2skw=
-github.com/minio/minio-go/v7 v7.0.21 h1:xrc4BQr1Fa4s5RwY0xfMjPZFJ1bcYBCCHYlngBdWV+k=
-github.com/minio/minio-go/v7 v7.0.21/go.mod h1:ei5JjmxwHaMrgsMrn4U/+Nmg+d8MKS1U2DAn1ou4+Do=
+github.com/minio/minio-go/v7 v7.0.22-0.20220210201649-8c600e5ae0e8 h1:ME70hdWOgZwQdvUMh1XBakfrY069Iq6FTtm9J9IZXxk=
+github.com/minio/minio-go/v7 v7.0.22-0.20220210201649-8c600e5ae0e8/go.mod h1:ei5JjmxwHaMrgsMrn4U/+Nmg+d8MKS1U2DAn1ou4+Do=
github.com/minio/pkg v1.0.3/go.mod h1:obU54TZ9QlMv0TRaDgQ/JTzf11ZSXxnSfLrm4tMtBP8=
github.com/minio/pkg v1.1.14 h1:9tGPH6p0YEsIOHOY3sh2Yl5Dn0JNTkNOdZW/p+MKIi4=
github.com/minio/pkg v1.1.14/go.mod h1:2WJAxesjzmPK9MnLZKm5n1hVYfBg04f2GQs6N5ImNU8=