fix: allow cluster bucket export to export single bucket (#4614)
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
@@ -82,29 +83,31 @@ func mainClusterBucketExport(ctx *cli.Context) error {
|
||||
aliasedURL = filepath.ToSlash(aliasedURL)
|
||||
aliasedURL = filepath.Clean(aliasedURL)
|
||||
_, bucket := url2Alias(aliasedURL)
|
||||
|
||||
r, e := client.ExportBucketMetadata(context.Background(), bucket)
|
||||
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to export bucket metadata.")
|
||||
|
||||
if bucket == "" {
|
||||
bucket = "bucket"
|
||||
}
|
||||
|
||||
// Create bucket metadata zip file
|
||||
tmpFile, e := os.CreateTemp("", fmt.Sprintf("%s-%s-metadata-", aliasedURL, bucket))
|
||||
tmpFile, e := os.CreateTemp("", fmt.Sprintf("%s-%s-metadata-", strings.ReplaceAll(aliasedURL, "/", "-"), bucket))
|
||||
fatalIf(probe.NewError(e), "Unable to download file data.")
|
||||
|
||||
ext := "zip"
|
||||
// Copy zip content to target download file
|
||||
_, e = io.Copy(tmpFile, r)
|
||||
fatalIf(probe.NewError(e), "Unable to download bucket metadata.")
|
||||
|
||||
// Close everything
|
||||
r.Close()
|
||||
tmpFile.Close()
|
||||
|
||||
// We use 4 bytes of the 32 bytes to identify the file.
|
||||
downloadPath := fmt.Sprintf("%s-%s-metadata.%s", aliasedURL, bucket, ext)
|
||||
// Create necessary directories.
|
||||
dir := filepath.Dir(downloadPath)
|
||||
if e := os.MkdirAll(dir, 0o755); e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(dir), "Unable to create download directory")
|
||||
}
|
||||
|
||||
fi, e := os.Stat(downloadPath)
|
||||
if e == nil && !fi.IsDir() {
|
||||
e = moveFile(downloadPath, downloadPath+"."+time.Now().Format(dateTimeFormatFilename))
|
||||
@@ -114,14 +117,12 @@ func mainClusterBucketExport(ctx *cli.Context) error {
|
||||
fatal(probe.NewError(e), "Unable to download file data")
|
||||
}
|
||||
}
|
||||
|
||||
fatalIf(probe.NewError(moveFile(tmpFile.Name(), downloadPath)), "Unable to rename downloaded data, file exists at %s", tmpFile.Name())
|
||||
|
||||
if !globalJSON {
|
||||
console.Infof("Bucket metadata successfully downloaded as %s\n", downloadPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
v := struct {
|
||||
File string `json:"file"`
|
||||
Key string `json:"key,omitempty"`
|
||||
|
||||
@@ -172,6 +172,7 @@ type catOpts struct {
|
||||
func parseCatSyntax(ctx *cli.Context) catOpts {
|
||||
// Validate command-line arguments.
|
||||
checkCatSyntax(ctx)
|
||||
|
||||
var o catOpts
|
||||
o.args = ctx.Args()
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ func mainRetentionClear(cliCtx *cli.Context) error {
|
||||
|
||||
target, versionID, rewind, withVersions, recursive, bucketMode := parseClearRetentionArgs(cliCtx)
|
||||
|
||||
fatalIfBucketLockNotEnabled(ctx, target)
|
||||
fatalIfBucketLockNotSupported(ctx, target)
|
||||
|
||||
if bucketMode {
|
||||
return clearBucketLock(target)
|
||||
|
||||
@@ -95,8 +95,8 @@ func (m retentionBucketMessage) String() string {
|
||||
return console.Colorize("RetentionSuccess", "Object lock configuration cleared successfully.")
|
||||
}
|
||||
// info/set command
|
||||
if m.Mode == "" {
|
||||
return console.Colorize("RetentionNotFound", "Object locking is not configured.")
|
||||
if !m.Mode.IsValid() {
|
||||
return console.Colorize("RetentionNotFound", "Object locking is not enabled.")
|
||||
}
|
||||
return console.Colorize("RetentionSuccess", fmt.Sprintf("Object locking '%s' is configured for %s.",
|
||||
console.Colorize("Mode", m.Mode), console.Colorize("Validity", m.Validity)))
|
||||
@@ -170,11 +170,10 @@ func parseRetentionValidity(validityStr string) (uint64, minio.ValidityUnit, *pr
|
||||
return validity, unit, nil
|
||||
}
|
||||
|
||||
func fatalIfBucketLockNotEnabled(ctx context.Context, aliasedURL string) {
|
||||
enabled, err := getBucketLockStatus(ctx, aliasedURL)
|
||||
fatalIf(err.Trace(), "Unable to get bucket lock configuration from `%s`", aliasedURL)
|
||||
if enabled != "Enabled" {
|
||||
fatalIf(errDummy().Trace(), "Remote bucket does not support locking `%s`", aliasedURL)
|
||||
func fatalIfBucketLockNotSupported(ctx context.Context, aliasedURL string) {
|
||||
_, err := getBucketLockStatus(ctx, aliasedURL)
|
||||
if err != nil {
|
||||
fatalIf(errDummy().Trace(), "Remote bucket `%s` does not support locking", aliasedURL)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -381,7 +381,7 @@ func mainRetentionInfo(cliCtx *cli.Context) error {
|
||||
|
||||
target, versionID, recursive, rewind, withVersions, bucketMode := parseInfoRetentionArgs(cliCtx)
|
||||
|
||||
fatalIfBucketLockNotEnabled(ctx, target)
|
||||
fatalIfBucketLockNotSupported(ctx, target)
|
||||
|
||||
if bucketMode {
|
||||
return showBucketLock(target)
|
||||
|
||||
@@ -148,7 +148,7 @@ func mainRetentionSet(cliCtx *cli.Context) error {
|
||||
|
||||
target, versionID, recursive, rewind, withVersions, mode, validity, unit, bypass, bucketMode := parseSetRetentionArgs(cliCtx)
|
||||
|
||||
fatalIfBucketLockNotEnabled(ctx, target)
|
||||
fatalIfBucketLockNotSupported(ctx, target)
|
||||
|
||||
if bucketMode {
|
||||
return setBucketLock(target, mode, validity, unit)
|
||||
|
||||
Reference in New Issue
Block a user