cleanup legal-hold/retention and update docs (#3197)
This commit is contained in:
+5
-5
@@ -930,7 +930,7 @@ func (f *fsClient) MakeBucket(region string, ignoreExisting, withLock bool) *pro
|
||||
}
|
||||
|
||||
// Set object lock configuration of bucket.
|
||||
func (f *fsClient) SetObjectLockConfig(mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit) *probe.Error {
|
||||
func (f *fsClient) SetObjectLockConfig(mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit) *probe.Error {
|
||||
return probe.NewError(APINotImplemented{
|
||||
API: "SetObjectLockConfig",
|
||||
APIType: "filesystem",
|
||||
@@ -938,8 +938,8 @@ func (f *fsClient) SetObjectLockConfig(mode *minio.RetentionMode, validity *uint
|
||||
}
|
||||
|
||||
// Get object lock configuration of bucket.
|
||||
func (f *fsClient) GetObjectLockConfig() (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, perr *probe.Error) {
|
||||
return nil, nil, nil, probe.NewError(APINotImplemented{
|
||||
func (f *fsClient) GetObjectLockConfig() (mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, err *probe.Error) {
|
||||
return "", 0, "", probe.NewError(APINotImplemented{
|
||||
API: "GetObjectLockConfig",
|
||||
APIType: "filesystem",
|
||||
})
|
||||
@@ -954,7 +954,7 @@ func (f *fsClient) GetAccessRules() (map[string]string, *probe.Error) {
|
||||
}
|
||||
|
||||
// Set object retention for a given object.
|
||||
func (f *fsClient) PutObjectRetention(mode *minio.RetentionMode, retainUntilDate *time.Time, bypassGovernance bool) *probe.Error {
|
||||
func (f *fsClient) PutObjectRetention(mode minio.RetentionMode, retainUntilDate time.Time, bypassGovernance bool) *probe.Error {
|
||||
return probe.NewError(APINotImplemented{
|
||||
API: "PutObjectRetention",
|
||||
APIType: "filesystem",
|
||||
@@ -962,7 +962,7 @@ func (f *fsClient) PutObjectRetention(mode *minio.RetentionMode, retainUntilDate
|
||||
}
|
||||
|
||||
// Set object legal hold for a given object.
|
||||
func (f *fsClient) PutObjectLegalHold(lhold *minio.LegalHoldStatus) *probe.Error {
|
||||
func (f *fsClient) PutObjectLegalHold(lhold minio.LegalHoldStatus) *probe.Error {
|
||||
return probe.NewError(APINotImplemented{
|
||||
API: "PutObjectLegalHold",
|
||||
APIType: "filesystem",
|
||||
|
||||
+64
-29
@@ -23,6 +23,7 @@ import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"io"
|
||||
"net"
|
||||
@@ -653,6 +654,17 @@ func (c *S3Client) notificationToEventsInfo(ninfo minio.NotificationInfo) []Even
|
||||
Port: record.Source.Port,
|
||||
UserAgent: record.Source.UserAgent,
|
||||
}
|
||||
} else if strings.HasPrefix(record.EventName, "s3:ObjectCreated:PutLegalHold") {
|
||||
eventsInfo[i] = EventInfo{
|
||||
Time: record.EventTime,
|
||||
Size: record.S3.Object.Size,
|
||||
UserMetadata: record.S3.Object.UserMetadata,
|
||||
Path: u.String(),
|
||||
Type: EventCreatePutLegalHold,
|
||||
Host: record.Source.Host,
|
||||
Port: record.Source.Port,
|
||||
UserAgent: record.Source.UserAgent,
|
||||
}
|
||||
} else {
|
||||
eventsInfo[i] = EventInfo{
|
||||
Time: record.EventTime,
|
||||
@@ -2120,57 +2132,80 @@ func (c *S3Client) ShareUpload(isRecursive bool, expires time.Duration, contentT
|
||||
}
|
||||
|
||||
// SetObjectLockConfig - Set object lock configurataion of bucket.
|
||||
func (c *S3Client) SetObjectLockConfig(mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit) *probe.Error {
|
||||
func (c *S3Client) SetObjectLockConfig(mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit) *probe.Error {
|
||||
bucket, _ := c.url2BucketAndObject()
|
||||
|
||||
err := c.api.SetBucketObjectLockConfig(bucket, mode, validity, unit)
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
// FIXME: This is too ugly, fix minio-go
|
||||
vuint := (uint)(validity)
|
||||
if mode != "" && vuint > 0 && unit != "" {
|
||||
e := c.api.SetBucketObjectLockConfig(bucket, &mode, &vuint, &unit)
|
||||
if e != nil {
|
||||
return probe.NewError(e).Trace(c.GetURL().String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
if mode == "" && vuint == 0 && unit == "" {
|
||||
e := c.api.SetBucketObjectLockConfig(bucket, nil, nil, nil)
|
||||
if e != nil {
|
||||
return probe.NewError(e).Trace(c.GetURL().String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return errInvalidArgument().Trace(c.GetURL().String())
|
||||
}
|
||||
|
||||
// PutObjectRetention - Set object retention for a given object.
|
||||
func (c *S3Client) PutObjectRetention(mode *minio.RetentionMode, retainUntilDate *time.Time, bypassGovernance bool) *probe.Error {
|
||||
func (c *S3Client) PutObjectRetention(mode minio.RetentionMode, retainUntilDate time.Time, bypassGovernance bool) *probe.Error {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
|
||||
opts := minio.PutObjectRetentionOptions{
|
||||
RetainUntilDate: retainUntilDate,
|
||||
Mode: mode,
|
||||
GovernanceBypass: bypassGovernance,
|
||||
}
|
||||
err := c.api.PutObjectRetention(bucket, object, opts)
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
if mode != "" && !retainUntilDate.IsZero() {
|
||||
opts := minio.PutObjectRetentionOptions{
|
||||
RetainUntilDate: &retainUntilDate,
|
||||
Mode: &mode,
|
||||
GovernanceBypass: bypassGovernance,
|
||||
}
|
||||
e := c.api.PutObjectRetention(bucket, object, opts)
|
||||
if e != nil {
|
||||
return probe.NewError(e).Trace(c.GetURL().String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
return errInvalidArgument().Trace(c.GetURL().String())
|
||||
}
|
||||
|
||||
// PutObjectLegalHold - Set object legal hold for a given object.
|
||||
func (c *S3Client) PutObjectLegalHold(lhold *minio.LegalHoldStatus) *probe.Error {
|
||||
func (c *S3Client) PutObjectLegalHold(lhold minio.LegalHoldStatus) *probe.Error {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
opts := minio.PutObjectLegalHoldOptions{
|
||||
Status: lhold,
|
||||
if lhold.IsValid() {
|
||||
opts := minio.PutObjectLegalHoldOptions{
|
||||
Status: &lhold,
|
||||
}
|
||||
e := c.api.PutObjectLegalHold(bucket, object, opts)
|
||||
if e != nil {
|
||||
return probe.NewError(e).Trace(c.GetURL().String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
err := c.api.PutObjectLegalHold(bucket, object, opts)
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
return nil
|
||||
return errInvalidArgument().Trace(c.GetURL().String())
|
||||
}
|
||||
|
||||
// GetObjectLockConfig - Get object lock configuration of bucket.
|
||||
func (c *S3Client) GetObjectLockConfig() (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, perr *probe.Error) {
|
||||
func (c *S3Client) GetObjectLockConfig() (minio.RetentionMode, uint64, minio.ValidityUnit, *probe.Error) {
|
||||
bucket, _ := c.url2BucketAndObject()
|
||||
|
||||
mode, validity, unit, err := c.api.GetBucketObjectLockConfig(bucket)
|
||||
if err != nil {
|
||||
return nil, nil, nil, probe.NewError(err)
|
||||
mode, validity, unit, e := c.api.GetBucketObjectLockConfig(bucket)
|
||||
if e != nil {
|
||||
return "", 0, "", probe.NewError(e).Trace(c.GetURL().String())
|
||||
}
|
||||
|
||||
return mode, validity, unit, nil
|
||||
if mode != nil && validity != nil && unit != nil {
|
||||
// FIXME: this is too ugly, fix minio-go
|
||||
vuint64 := uint64(*validity)
|
||||
return *mode, vuint64, *unit, nil
|
||||
}
|
||||
|
||||
return "", 0, "", probe.NewError(fmt.Errorf("No object lock configuration set on %s", bucket)).Trace(c.GetURL().String())
|
||||
}
|
||||
|
||||
// GetObjectTagging - Get Object Tags
|
||||
|
||||
+10
-6
@@ -51,8 +51,9 @@ type Client interface {
|
||||
|
||||
// Bucket operations
|
||||
MakeBucket(region string, ignoreExisting, withLock bool) *probe.Error
|
||||
SetObjectLockConfig(mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit) *probe.Error
|
||||
GetObjectLockConfig() (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, perr *probe.Error)
|
||||
// Object lock config
|
||||
SetObjectLockConfig(mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit) *probe.Error
|
||||
GetObjectLockConfig() (mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, perr *probe.Error)
|
||||
|
||||
// Access policy operations.
|
||||
GetAccess() (access string, policyJSON string, error *probe.Error)
|
||||
@@ -68,9 +69,10 @@ type Client interface {
|
||||
// I/O operations with metadata.
|
||||
Get(sse encrypt.ServerSide) (reader io.ReadCloser, err *probe.Error)
|
||||
Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, md5, disableMultipart bool) (n int64, err *probe.Error)
|
||||
|
||||
// Object Locking related API
|
||||
PutObjectRetention(mode *minio.RetentionMode, retainUntilDate *time.Time, bypassGovernance bool) *probe.Error
|
||||
PutObjectLegalHold(hold *minio.LegalHoldStatus) *probe.Error
|
||||
PutObjectRetention(mode minio.RetentionMode, retainUntilDate time.Time, bypassGovernance bool) *probe.Error
|
||||
PutObjectLegalHold(hold minio.LegalHoldStatus) *probe.Error
|
||||
|
||||
// I/O operations with expiration
|
||||
ShareDownload(expires time.Duration) (string, *probe.Error)
|
||||
@@ -103,12 +105,14 @@ type ClientContent struct {
|
||||
UserMetadata map[string]string
|
||||
ETag string
|
||||
Expires time.Time
|
||||
Retention bool
|
||||
RetentionEnabled bool
|
||||
RetentionMode string
|
||||
RetentionDuration string
|
||||
BypassGovernance bool
|
||||
LegalHoldEnabled bool
|
||||
LegalHold string
|
||||
Err *probe.Error
|
||||
|
||||
Err *probe.Error
|
||||
}
|
||||
|
||||
// Config - see http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
|
||||
|
||||
+34
-14
@@ -290,7 +290,7 @@ func putTargetRetention(ctx context.Context, alias string, urlStr string, metada
|
||||
retainUntilDate = t.UTC()
|
||||
}
|
||||
}
|
||||
if err := targetClnt.PutObjectRetention(&lockMode, &retainUntilDate, false); err != nil {
|
||||
if err := targetClnt.PutObjectRetention(lockMode, retainUntilDate, false); err != nil {
|
||||
return err.Trace(alias, urlStr)
|
||||
}
|
||||
return nil
|
||||
@@ -407,22 +407,42 @@ func uploadSourceToTargetURL(ctx context.Context, urls URLs, progress io.Reader,
|
||||
|
||||
var err *probe.Error
|
||||
var metadata = map[string]string{}
|
||||
var mode, until, legalHold string
|
||||
|
||||
var mode, until string
|
||||
var pErr error
|
||||
// add object retention fields in metadata
|
||||
if urls.TargetContent.RetentionDuration != "" && urls.TargetContent.RetentionMode != "" {
|
||||
// add object retention fields in metadata for target, if target wants
|
||||
// to override defaults from source, usually happens in `cp` command.
|
||||
// for the most part source metadata is copied over.
|
||||
if urls.TargetContent.RetentionEnabled {
|
||||
m := minio.RetentionMode(strings.ToUpper(urls.TargetContent.RetentionMode))
|
||||
|
||||
dur, unit := parseRetentionValidity(urls.TargetContent.RetentionDuration, m)
|
||||
var dur uint64
|
||||
var unit minio.ValidityUnit
|
||||
dur, unit, err = parseRetentionValidity(urls.TargetContent.RetentionDuration, m)
|
||||
if err != nil {
|
||||
return urls.WithError(err.Trace(targetURL.String()))
|
||||
}
|
||||
|
||||
mode = urls.TargetContent.RetentionMode
|
||||
|
||||
until, pErr = getRetainUntilDate(dur, unit)
|
||||
until, err = getRetainUntilDate(dur, unit)
|
||||
if err != nil {
|
||||
return urls.WithError(probe.NewError(pErr).Trace(sourceURL.String()))
|
||||
return urls.WithError(err.Trace(sourceURL.String()))
|
||||
}
|
||||
}
|
||||
|
||||
// add object legal hold fields in metadata for target, if target wants
|
||||
// to override defaults from source, usually happens in `cp` command.
|
||||
// for the most part source metadata is copied over.
|
||||
if urls.TargetContent.LegalHoldEnabled {
|
||||
switch minio.LegalHoldStatus(urls.TargetContent.LegalHold) {
|
||||
case minio.LegalHoldDisabled:
|
||||
case minio.LegalHoldEnabled:
|
||||
default:
|
||||
return urls.WithError(errInvalidArgument().Trace(urls.TargetContent.LegalHold))
|
||||
}
|
||||
legalHold = urls.TargetContent.LegalHold
|
||||
}
|
||||
|
||||
for k, v := range urls.SourceContent.UserMetadata {
|
||||
metadata[http.CanonicalHeaderKey(k)] = v
|
||||
}
|
||||
@@ -442,14 +462,14 @@ func uploadSourceToTargetURL(ctx context.Context, urls URLs, progress io.Reader,
|
||||
}
|
||||
|
||||
sourcePath := filepath.ToSlash(sourceURL.Path)
|
||||
if urls.SourceContent.Retention {
|
||||
if urls.SourceContent.RetentionEnabled {
|
||||
err = putTargetRetention(ctx, targetAlias, targetURL.String(), metadata)
|
||||
return urls.WithError(err.Trace(sourceURL.String()))
|
||||
}
|
||||
err = copySourceToTargetURL(targetAlias, targetURL.String(), sourcePath, mode, until, urls.TargetContent.LegalHold, length,
|
||||
progress, srcSSE, tgtSSE, filterMetadata(metadata), urls.DisableMultipart)
|
||||
err = copySourceToTargetURL(targetAlias, targetURL.String(), sourcePath, mode, until,
|
||||
legalHold, length, progress, srcSSE, tgtSSE, filterMetadata(metadata), urls.DisableMultipart)
|
||||
} else {
|
||||
if urls.SourceContent.Retention {
|
||||
if urls.SourceContent.RetentionEnabled {
|
||||
// If no metadata populated already by the caller
|
||||
// just do a Stat() to obtain the metadata.
|
||||
if len(metadata) == 0 {
|
||||
@@ -481,11 +501,11 @@ func uploadSourceToTargetURL(ctx context.Context, urls URLs, progress io.Reader,
|
||||
|
||||
if isReadAt(reader) {
|
||||
_, err = putTargetStream(ctx, targetAlias, targetURL.String(), mode, until,
|
||||
urls.TargetContent.LegalHold, reader, length, filterMetadata(metadata),
|
||||
legalHold, reader, length, filterMetadata(metadata),
|
||||
progress, tgtSSE, urls.MD5, urls.DisableMultipart)
|
||||
} else {
|
||||
_, err = putTargetStream(ctx, targetAlias, targetURL.String(), mode, until,
|
||||
urls.TargetContent.LegalHold, io.LimitReader(reader, length),
|
||||
legalHold, io.LimitReader(reader, length),
|
||||
length, filterMetadata(metadata), progress, tgtSSE, urls.MD5,
|
||||
urls.DisableMultipart)
|
||||
}
|
||||
|
||||
@@ -473,17 +473,25 @@ func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]p
|
||||
// update Object retention related fields
|
||||
if session != nil {
|
||||
cpURLs.TargetContent.RetentionMode = session.Header.CommandStringFlags[rmFlag]
|
||||
if cpURLs.TargetContent.RetentionMode != "" {
|
||||
cpURLs.TargetContent.RetentionEnabled = true
|
||||
}
|
||||
cpURLs.TargetContent.RetentionDuration = session.Header.CommandStringFlags[rdFlag]
|
||||
cpURLs.TargetContent.LegalHold = session.Header.CommandStringFlags[lhFlag]
|
||||
if cpURLs.TargetContent.LegalHold != "" {
|
||||
cpURLs.TargetContent.LegalHoldEnabled = true
|
||||
}
|
||||
} else {
|
||||
if rm := cli.String(rmFlag); rm != "" {
|
||||
cpURLs.TargetContent.RetentionMode = rm
|
||||
cpURLs.TargetContent.RetentionEnabled = true
|
||||
}
|
||||
if rd := cli.String(rdFlag); rd != "" {
|
||||
cpURLs.TargetContent.RetentionDuration = rd
|
||||
}
|
||||
if lh := cli.String(lhFlag); lh != "" {
|
||||
cpURLs.TargetContent.LegalHold = lh
|
||||
cpURLs.TargetContent.LegalHoldEnabled = true
|
||||
}
|
||||
}
|
||||
if cli.String("attr") != "" {
|
||||
|
||||
+22
-24
@@ -18,7 +18,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -39,26 +38,26 @@ var (
|
||||
)
|
||||
var legalHoldCmd = cli.Command{
|
||||
Name: "legalhold",
|
||||
Usage: "set object legal hold for objects",
|
||||
Usage: "set legal hold for object(s)",
|
||||
Action: mainLegalHold,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(lhFlags, globalFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET [ON | OFF]
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET [ON | OFF]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
|
||||
EXAMPLES:
|
||||
1. Enable object legal hold for objects in a given prefix
|
||||
$ {{.HelpName}} myminio/mybucket/prefix ON --recursive
|
||||
EXAMPLES:
|
||||
1. Enable legal hold on a specific object
|
||||
$ {{.HelpName}} myminio/mybucket/prefix/obj.csv ON
|
||||
|
||||
2. Enable legal hold on a specific object
|
||||
$ {{.HelpName}} myminio/mybucket/prefix/obj.csv ON
|
||||
2. Enable object legal hold recursively for all objects at a prefix
|
||||
$ {{.HelpName}} myminio/mybucket/prefix ON --recursive
|
||||
`,
|
||||
}
|
||||
|
||||
@@ -86,18 +85,18 @@ func (l legalHoldCmdMessage) JSON() string {
|
||||
}
|
||||
|
||||
// setRetention - Set Retention for all objects within a given prefix.
|
||||
func setLegalHold(urlStr string, lhold *minio.LegalHoldStatus, isRecursive bool) error {
|
||||
func setLegalHold(urlStr string, lhold minio.LegalHoldStatus, isRecursive bool) error {
|
||||
clnt, err := newClient(urlStr)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(), "Cannot parse the provided url.")
|
||||
}
|
||||
if !isRecursive {
|
||||
probeErr := clnt.PutObjectLegalHold(lhold)
|
||||
if probeErr != nil {
|
||||
errorIf(probeErr.Trace(urlStr), "Failed to set legal hold on `"+urlStr+"` successfully")
|
||||
err = clnt.PutObjectLegalHold(lhold)
|
||||
if err != nil {
|
||||
errorIf(err.Trace(urlStr), "Failed to set legal hold on `"+urlStr+"` successfully")
|
||||
} else {
|
||||
printMsg(legalHoldCmdMessage{
|
||||
LegalHold: *lhold,
|
||||
LegalHold: lhold,
|
||||
Status: "success",
|
||||
URLPath: urlStr,
|
||||
})
|
||||
@@ -127,7 +126,7 @@ func setLegalHold(urlStr string, lhold *minio.LegalHoldStatus, isRecursive bool)
|
||||
} else {
|
||||
if globalJSON {
|
||||
printMsg(legalHoldCmdMessage{
|
||||
LegalHold: *lhold,
|
||||
LegalHold: lhold,
|
||||
Status: "success",
|
||||
URLPath: content.URL.Path,
|
||||
})
|
||||
@@ -152,15 +151,14 @@ func mainLegalHold(ctx *cli.Context) error {
|
||||
args := ctx.Args()
|
||||
|
||||
var urlStr string
|
||||
var lhold *minio.LegalHoldStatus
|
||||
var lhold minio.LegalHoldStatus
|
||||
switch l := len(args); l {
|
||||
case 2:
|
||||
urlStr = args[0]
|
||||
h := minio.LegalHoldStatus(strings.ToUpper(args[1]))
|
||||
if !h.IsValid() {
|
||||
fatalIf(probe.NewError(errors.New("invalid argument")), "invalid legal hold status '%v'", h)
|
||||
lhold = minio.LegalHoldStatus(strings.ToUpper(args[1]))
|
||||
if !lhold.IsValid() {
|
||||
fatalIf(errInvalidArgument().Trace(urlStr), "invalid legal hold status '%v'", lhold)
|
||||
}
|
||||
lhold = &h
|
||||
default:
|
||||
cli.ShowCommandHelpAndExit(ctx, "legalhold", 1)
|
||||
}
|
||||
|
||||
+34
-56
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* MinIO Client (C) 2019 MinIO, Inc.
|
||||
* MinIO Client (C) 2019-2020 MinIO, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -49,7 +48,7 @@ var lockCmd = cli.Command{
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET [governance | compliance] [VALIDITY]
|
||||
{{.HelpName}} [FLAGS] TARGET [governance | compliance] VALIDITY
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
@@ -71,19 +70,19 @@ EXAMPLES:
|
||||
|
||||
// Structured message depending on the type of console.
|
||||
type lockCmdMessage struct {
|
||||
Enabled string `json:"enabled"`
|
||||
Mode *minio.RetentionMode `json:"mode"`
|
||||
Validity *string `json:"validity"`
|
||||
Status string `json:"status"`
|
||||
Enabled string `json:"enabled"`
|
||||
Mode minio.RetentionMode `json:"mode"`
|
||||
Validity string `json:"validity"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// Colorized message for console printing.
|
||||
func (m lockCmdMessage) String() string {
|
||||
if m.Mode == nil {
|
||||
return "No object lock configuration is enabled"
|
||||
if m.Mode == "" {
|
||||
return "Object lock configuration cleared successfully"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s mode is enabled for %s", console.Colorize("Mode", *m.Mode), console.Colorize("Validity", *m.Validity))
|
||||
return fmt.Sprintf("%s mode is enabled for %s", console.Colorize("Mode", m.Mode), console.Colorize("Validity", m.Validity))
|
||||
}
|
||||
|
||||
// JSON'ified message for scripting.
|
||||
@@ -94,75 +93,53 @@ func (m lockCmdMessage) JSON() string {
|
||||
}
|
||||
|
||||
// lock - set/get object lock configuration.
|
||||
func lock(urlStr string, mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, clearLock bool) error {
|
||||
func lock(urlStr string, mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, clearLock bool) error {
|
||||
client, err := newClient(urlStr)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(), "Cannot parse the provided url.")
|
||||
}
|
||||
|
||||
s3Client, ok := client.(*S3Client)
|
||||
if !ok {
|
||||
fatalIf(errDummy().Trace(), "The provided url doesn't point to a S3 server.")
|
||||
}
|
||||
|
||||
validityStr := func() *string {
|
||||
if validity == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
unitStr := "d"
|
||||
if *unit == minio.Years {
|
||||
unitStr = "y"
|
||||
}
|
||||
s := fmt.Sprint(*validity, unitStr)
|
||||
return &s
|
||||
}
|
||||
|
||||
if clearLock || mode != nil {
|
||||
err = s3Client.SetObjectLockConfig(mode, validity, unit)
|
||||
if clearLock || mode != "" {
|
||||
err = client.SetObjectLockConfig(mode, validity, unit)
|
||||
fatalIf(err, "Cannot enable object lock configuration on the specified bucket.")
|
||||
} else {
|
||||
mode, validity, unit, err = s3Client.GetObjectLockConfig()
|
||||
mode, validity, unit, err = client.GetObjectLockConfig()
|
||||
fatalIf(err, "Cannot get object lock configuration on the specified bucket.")
|
||||
}
|
||||
|
||||
printMsg(lockCmdMessage{
|
||||
Enabled: "Enabled",
|
||||
Mode: mode,
|
||||
Validity: validityStr(),
|
||||
Validity: fmt.Sprintf("%d%s", validity, unit),
|
||||
Status: "success",
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseRetentionValidity(validityStr string, m minio.RetentionMode) (*uint, *minio.ValidityUnit) {
|
||||
func parseRetentionValidity(validityStr string, m minio.RetentionMode) (uint64, minio.ValidityUnit, *probe.Error) {
|
||||
if !m.IsValid() {
|
||||
fatalIf(probe.NewError(errors.New("invalid argument")), "invalid retention mode '%v'", m)
|
||||
return 0, "", errInvalidArgument().Trace(fmt.Sprintf("invalid retention mode '%v'", m))
|
||||
}
|
||||
|
||||
unitStr := string(validityStr[len(validityStr)-1])
|
||||
validityStr = validityStr[:len(validityStr)-1]
|
||||
ui64, err := strconv.ParseUint(validityStr, 10, 64)
|
||||
if err != nil {
|
||||
fatalIf(probe.NewError(errors.New("invalid argument")), "invalid validity '%v'", validityStr)
|
||||
validity, e := strconv.ParseUint(validityStr, 10, 64)
|
||||
if e != nil {
|
||||
return 0, "", probe.NewError(e).Trace(validityStr)
|
||||
}
|
||||
|
||||
u := uint(ui64)
|
||||
validity := &u
|
||||
var unit *minio.ValidityUnit
|
||||
var unit minio.ValidityUnit
|
||||
switch unitStr {
|
||||
case "d", "D":
|
||||
d := minio.Days
|
||||
unit = &d
|
||||
unit = minio.Days
|
||||
case "y", "Y":
|
||||
y := minio.Years
|
||||
unit = &y
|
||||
unit = minio.Years
|
||||
default:
|
||||
fatalIf(probe.NewError(errors.New("invalid argument")), "invalid validity format '%v'", unitStr)
|
||||
return 0, "", errInvalidArgument().Trace(unitStr)
|
||||
}
|
||||
|
||||
return validity, unit
|
||||
return validity, unit, nil
|
||||
}
|
||||
|
||||
// main for lock command.
|
||||
@@ -176,24 +153,25 @@ func mainLock(ctx *cli.Context) error {
|
||||
args := ctx.Args()
|
||||
|
||||
var urlStr string
|
||||
var mode *minio.RetentionMode
|
||||
var validity *uint
|
||||
var unit *minio.ValidityUnit
|
||||
var mode minio.RetentionMode
|
||||
var validity uint64
|
||||
var unit minio.ValidityUnit
|
||||
var err *probe.Error
|
||||
|
||||
switch l := len(args); l {
|
||||
case 1:
|
||||
urlStr = args[0]
|
||||
|
||||
case 3:
|
||||
urlStr = args[0]
|
||||
if clearLock {
|
||||
fatalIf(probe.NewError(errors.New("invalid argument")), "clear flag must be passed with target alone")
|
||||
fatalIf(errInvalidArgument().Trace(urlStr), "clear flag must be passed with target alone")
|
||||
}
|
||||
|
||||
m := minio.RetentionMode(strings.ToUpper(args[1]))
|
||||
mode = &m
|
||||
validity, unit = parseRetentionValidity(args[2], m)
|
||||
|
||||
mode = minio.RetentionMode(strings.ToUpper(args[1]))
|
||||
validity, unit, err = parseRetentionValidity(args[2], mode)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(args...), "unable to parse input arguments")
|
||||
}
|
||||
default:
|
||||
cli.ShowCommandHelpAndExit(ctx, "lock", 1)
|
||||
}
|
||||
|
||||
+1
-1
@@ -325,6 +325,7 @@ var appCmds = []cli.Command{
|
||||
findCmd,
|
||||
sqlCmd,
|
||||
statCmd,
|
||||
mvCmd,
|
||||
treeCmd,
|
||||
duCmd,
|
||||
lockCmd,
|
||||
@@ -339,7 +340,6 @@ var appCmds = []cli.Command{
|
||||
adminCmd,
|
||||
configCmd,
|
||||
updateCmd,
|
||||
mvCmd,
|
||||
}
|
||||
|
||||
func registerApp(name string) *cli.App {
|
||||
|
||||
+9
-8
@@ -288,7 +288,7 @@ func (mj *mirrorJob) doMirrorWatch(ctx context.Context, targetPath string, tgtSS
|
||||
}
|
||||
_, err = targetClient.Stat(false, false, tgtSSE)
|
||||
if err == nil {
|
||||
if !sURLs.SourceContent.Retention {
|
||||
if !sURLs.SourceContent.RetentionEnabled && !sURLs.SourceContent.LegalHoldEnabled {
|
||||
return sURLs.WithError(probe.NewError(ObjectAlreadyExists{}))
|
||||
}
|
||||
} // doesn't exist
|
||||
@@ -456,11 +456,12 @@ func (mj *mirrorJob) watchMirrorEvents(ctx context.Context, events []EventInfo)
|
||||
mirrorURL := URLs{
|
||||
SourceAlias: sourceAlias,
|
||||
SourceContent: &ClientContent{
|
||||
URL: *sourceURL,
|
||||
Retention: event.Type == EventCreatePutRetention,
|
||||
Size: event.Size,
|
||||
Time: sourceModTime,
|
||||
Metadata: event.UserMetadata,
|
||||
URL: *sourceURL,
|
||||
RetentionEnabled: event.Type == EventCreatePutRetention,
|
||||
LegalHoldEnabled: event.Type == EventCreatePutLegalHold,
|
||||
Size: event.Size,
|
||||
Time: sourceModTime,
|
||||
Metadata: event.UserMetadata,
|
||||
},
|
||||
TargetAlias: targetAlias,
|
||||
TargetContent: &ClientContent{URL: *targetURL},
|
||||
@@ -830,7 +831,7 @@ func runMirror(srcURL, dstURL string, ctx *cli.Context, encKeyDB map[string][]pr
|
||||
continue
|
||||
}
|
||||
// object lock configuration set on bucket
|
||||
if mode != nil {
|
||||
if mode != "" {
|
||||
errorIf(newDstClt.SetObjectLockConfig(mode, validity, unit),
|
||||
"Unable to set object lock config in `"+newTgtURL+"`.")
|
||||
}
|
||||
@@ -871,7 +872,7 @@ func runMirror(srcURL, dstURL string, ctx *cli.Context, encKeyDB map[string][]pr
|
||||
}
|
||||
|
||||
// object lock configuration set on bucket
|
||||
if mode != nil {
|
||||
if mode != "" {
|
||||
err = dstClt.SetObjectLockConfig(mode, validity, unit)
|
||||
errorIf(err, "Unable to set object lock config in `"+dstURL+"`.")
|
||||
if err != nil && mj.multiMasterEnable {
|
||||
|
||||
+52
-80
@@ -17,7 +17,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -48,7 +47,7 @@ var bypass = "bypass"
|
||||
|
||||
var retentionCmd = cli.Command{
|
||||
Name: "retention",
|
||||
Usage: "set object retention for objects with a given prefix",
|
||||
Usage: "set retention for object(s)",
|
||||
Action: mainRetention,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(rFlags, globalFlags...),
|
||||
@@ -56,7 +55,7 @@ var retentionCmd = cli.Command{
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET [governance | compliance] [VALIDITY]
|
||||
{{.HelpName}} [FLAGS] TARGET [governance | compliance] VALIDITY
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
@@ -65,19 +64,18 @@ VALIDITY:
|
||||
This argument must be formatted like Nd or Ny where 'd' denotes days and 'y' denotes years e.g. 10d, 3y.
|
||||
|
||||
EXAMPLES:
|
||||
1. Set object retention for a specific object
|
||||
1. Set object retention for a specific object
|
||||
$ {{.HelpName}} myminio/mybucket/prefix/obj.csv compliance 30d
|
||||
|
||||
2. Set object retention for objects in a given prefix
|
||||
2. Set object retention for recursively for all objects at a given prefix
|
||||
$ {{.HelpName}} myminio/mybucket/prefix compliance 30d --recursive
|
||||
|
||||
`,
|
||||
`,
|
||||
}
|
||||
|
||||
// Structured message depending on the type of console.
|
||||
type retentionCmdMessage struct {
|
||||
Mode minio.RetentionMode `json:"mode"`
|
||||
Validity *string `json:"validity"`
|
||||
Validity string `json:"validity"`
|
||||
URLPath string `json:"urlpath"`
|
||||
Status string `json:"status"`
|
||||
Err error `json:"error"`
|
||||
@@ -86,27 +84,30 @@ type retentionCmdMessage struct {
|
||||
// Colorized message for console printing.
|
||||
func (m retentionCmdMessage) String() string {
|
||||
if m.Err != nil {
|
||||
return console.Colorize("RetentionMessageFailure", "Cannot set object retention on `"+m.URLPath+"`."+m.Err.Error())
|
||||
return console.Colorize("RetentionMessageFailure", fmt.Sprintf("Cannot set object retention on `%s`: %s", m.URLPath, m.Err))
|
||||
}
|
||||
return ""
|
||||
return console.Colorize("RetentionSuccess", fmt.Sprintf("Object retention successfully set for `%s`", m.URLPath))
|
||||
}
|
||||
|
||||
// JSON'ified message for scripting.
|
||||
func (m retentionCmdMessage) JSON() string {
|
||||
if m.Err != nil {
|
||||
m.Status = "failure"
|
||||
}
|
||||
msgBytes, e := json.MarshalIndent(m, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(msgBytes)
|
||||
}
|
||||
|
||||
func getRetainUntilDate(validity *uint, unit *minio.ValidityUnit) (string, error) {
|
||||
if validity == nil {
|
||||
return "", fmt.Errorf("invalid validity '%v'", validity)
|
||||
func getRetainUntilDate(validity uint64, unit minio.ValidityUnit) (string, *probe.Error) {
|
||||
if validity == 0 {
|
||||
return "", probe.NewError(fmt.Errorf("invalid validity '%v'", validity))
|
||||
}
|
||||
t := UTCNow()
|
||||
if *unit == minio.Years {
|
||||
t = t.AddDate(int(*validity), 0, 0)
|
||||
if unit == minio.Years {
|
||||
t = t.AddDate(int(validity), 0, 0)
|
||||
} else {
|
||||
t = t.AddDate(0, 0, int(*validity))
|
||||
t = t.AddDate(0, 0, int(validity))
|
||||
}
|
||||
timeStr := t.Format(time.RFC3339)
|
||||
|
||||
@@ -114,7 +115,7 @@ func getRetainUntilDate(validity *uint, unit *minio.ValidityUnit) (string, error
|
||||
}
|
||||
|
||||
// setRetention - Set Retention for all objects within a given prefix.
|
||||
func setRetention(urlStr string, mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, bypassGovernance, isRecursive bool) error {
|
||||
func setRetention(urlStr string, mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, bypassGovernance, isRecursive bool) error {
|
||||
clnt, err := newClient(urlStr)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(), "Cannot parse the provided url.")
|
||||
@@ -128,21 +129,7 @@ func setRetention(urlStr string, mode *minio.RetentionMode, validity *uint, unit
|
||||
|
||||
alias, _, _ := mustExpandAlias(urlStr)
|
||||
|
||||
validityStr := func() *string {
|
||||
if validity == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
unitStr := "d"
|
||||
if *unit == minio.Years {
|
||||
unitStr = "y"
|
||||
}
|
||||
s := fmt.Sprint(*validity, unitStr)
|
||||
return &s
|
||||
}
|
||||
|
||||
var cErr error
|
||||
errorsFound := false
|
||||
for content := range clnt.List(isRecursive, false, false, DirNone) {
|
||||
if content.Err != nil {
|
||||
errorIf(content.Err.Trace(clnt.GetURL().String()), "Unable to list folder.")
|
||||
@@ -151,46 +138,36 @@ func setRetention(urlStr string, mode *minio.RetentionMode, validity *uint, unit
|
||||
}
|
||||
timeStr, err := getRetainUntilDate(validity, unit)
|
||||
if err != nil {
|
||||
errorIf(content.Err.Trace(clnt.GetURL().String()), "Invalid retention date")
|
||||
errorIf(err.Trace(clnt.GetURL().String()), "Invalid retention date")
|
||||
continue
|
||||
}
|
||||
retainUntil, e := time.Parse(time.RFC3339, timeStr)
|
||||
if e != nil {
|
||||
errorIf(content.Err.Trace(clnt.GetURL().String()), "Invalid retention date")
|
||||
errorIf(probe.NewError(e).Trace(clnt.GetURL().String()), "Invalid retention date")
|
||||
continue
|
||||
}
|
||||
|
||||
newClnt, perr := newClientFromAlias(alias, content.URL.String())
|
||||
if perr != nil {
|
||||
errorIf(content.Err.Trace(clnt.GetURL().String()), "Invalid URL")
|
||||
newClnt, err := newClientFromAlias(alias, content.URL.String())
|
||||
if err != nil {
|
||||
errorIf(err.Trace(clnt.GetURL().String()), "Invalid URL")
|
||||
continue
|
||||
}
|
||||
probeErr := newClnt.PutObjectRetention(mode, &retainUntil, bypassGovernance)
|
||||
if probeErr != nil {
|
||||
errorsFound = true
|
||||
err = newClnt.PutObjectRetention(mode, retainUntil, bypassGovernance)
|
||||
if err != nil {
|
||||
printMsg(retentionCmdMessage{
|
||||
Mode: *mode,
|
||||
Validity: validityStr(),
|
||||
Mode: mode,
|
||||
Validity: fmt.Sprintf("%d%s", validity, unit),
|
||||
Status: "failure",
|
||||
URLPath: content.URL.Path,
|
||||
Err: probeErr.ToGoError(),
|
||||
URLPath: urlJoinPath(alias, content.URL.Path),
|
||||
Err: err.ToGoError(),
|
||||
})
|
||||
} else {
|
||||
if globalJSON {
|
||||
printMsg(retentionCmdMessage{
|
||||
Mode: *mode,
|
||||
Validity: validityStr(),
|
||||
Status: "success",
|
||||
URLPath: content.URL.Path,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
if cErr == nil && !globalJSON {
|
||||
if errorsFound {
|
||||
console.Print(console.Colorize("RetentionPartialFailure", fmt.Sprintf("Errors found while setting retention on objects with prefix `%s`.\n", urlStr)))
|
||||
} else {
|
||||
console.Print(console.Colorize("RetentionSuccess", fmt.Sprintf("Object retention successfully set for `%s`.\n", urlStr)))
|
||||
printMsg(retentionCmdMessage{
|
||||
Mode: mode,
|
||||
Validity: fmt.Sprintf("%d%s", validity, unit),
|
||||
Status: "success",
|
||||
URLPath: urlJoinPath(alias, content.URL.Path),
|
||||
})
|
||||
}
|
||||
}
|
||||
return cErr
|
||||
@@ -204,40 +181,35 @@ func mainRetention(ctx *cli.Context) error {
|
||||
args := ctx.Args()
|
||||
|
||||
var urlStr string
|
||||
var mode *minio.RetentionMode
|
||||
var validity *uint
|
||||
var unit *minio.ValidityUnit
|
||||
var mode minio.RetentionMode
|
||||
var validity uint64
|
||||
var unit minio.ValidityUnit
|
||||
|
||||
switch l := len(args); l {
|
||||
case 3:
|
||||
urlStr = args[0]
|
||||
m := minio.RetentionMode(strings.ToUpper(args[1]))
|
||||
if !m.IsValid() {
|
||||
fatalIf(probe.NewError(errors.New("invalid argument")), "invalid retention mode '%v'", m)
|
||||
mode = minio.RetentionMode(strings.ToUpper(args[1]))
|
||||
if !mode.IsValid() {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "invalid retention mode '%v'", mode)
|
||||
}
|
||||
|
||||
mode = &m
|
||||
|
||||
validityStr := args[2]
|
||||
unitStr := string(validityStr[len(validityStr)-1])
|
||||
|
||||
unitStr := validityStr[len(validityStr)-1]
|
||||
validityStr = validityStr[:len(validityStr)-1]
|
||||
ui64, err := strconv.ParseUint(validityStr, 10, 64)
|
||||
if err != nil {
|
||||
fatalIf(probe.NewError(errors.New("invalid argument")), "invalid validity '%v'", args[2])
|
||||
|
||||
var e error
|
||||
validity, e = strconv.ParseUint(validityStr, 10, 64)
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(urlStr), "invalid validity '%v'", validityStr)
|
||||
}
|
||||
u := uint(ui64)
|
||||
validity = &u
|
||||
|
||||
switch unitStr {
|
||||
case "d", "D":
|
||||
d := minio.Days
|
||||
unit = &d
|
||||
case "y", "Y":
|
||||
y := minio.Years
|
||||
unit = &y
|
||||
case 'd', 'D':
|
||||
unit = minio.Days
|
||||
case 'y', 'Y':
|
||||
unit = minio.Years
|
||||
default:
|
||||
fatalIf(probe.NewError(errors.New("invalid argument")), "invalid validity format '%v'", args[2])
|
||||
fatalIf(errInvalidArgument().Trace(urlStr), "invalid validity format '%v'", unitStr)
|
||||
}
|
||||
default:
|
||||
cli.ShowCommandHelpAndExit(ctx, "retention", 1)
|
||||
|
||||
+10
-3
@@ -33,13 +33,20 @@ const (
|
||||
// EventCreateCopy notifies when there was a server side copy
|
||||
EventCreateCopy EventType = "ObjectCreated:Copy"
|
||||
|
||||
// EventCreatePutRetention notifies when a retention configuration is added to an object
|
||||
EventCreatePutRetention EventType = "ObjectCreated:PutRetention"
|
||||
// EventRemove notifies when a new object is deleted
|
||||
EventRemove = "ObjectRemoved"
|
||||
|
||||
// Following are MinIO server specific events
|
||||
|
||||
// EventCreatePutRetention notifies when a retention configuration is added to an object
|
||||
EventCreatePutRetention EventType = "ObjectCreated:PutRetention"
|
||||
|
||||
// EventCreatePutLegalHold notifies when a legal hold configuration is added to an object
|
||||
EventCreatePutLegalHold EventType = "ObjectCreated:PutLegalHold"
|
||||
|
||||
// EventAccessed notifies when an object is accessed.
|
||||
EventAccessed = "ObjectAccessed"
|
||||
// EventAccessedRead notifies when an object is accessed (specifically read).
|
||||
// EventAccessedRead notifies when an object is accessed (specifically read/get).
|
||||
EventAccessedRead = "ObjectAccessed:Read"
|
||||
// EventAccessedStat notifies when an object is accessed (specifically stat).
|
||||
EventAccessedStat = "ObjectAccessed:Stat"
|
||||
|
||||
@@ -3,33 +3,33 @@
|
||||
MinIO Client (mc) provides a modern alternative to UNIX commands like ls, cat, cp, mirror, diff etc. It supports filesystems and Amazon S3 compatible cloud storage service (AWS Signature v2 and v4).
|
||||
|
||||
```
|
||||
ls list buckets and objects
|
||||
tree list buckets and objects in a tree format
|
||||
mb make a bucket
|
||||
rb remove a bucket
|
||||
cat display object contents
|
||||
head display first 'n' lines of an object
|
||||
pipe stream STDIN to an object
|
||||
share generate URL for temporary access to an object
|
||||
cp copy objects
|
||||
mirror synchronize objects to a remote site
|
||||
find search for objects
|
||||
sql run sql queries on objects
|
||||
stat stat contents of objects
|
||||
lock set and get object lock configuration
|
||||
retention set object retention for objects with a given prefix
|
||||
legalhold set object legal hold for objects with a given prefix
|
||||
diff list differences in object name, size, and date between buckets
|
||||
rm remove objects
|
||||
event manage object notifications
|
||||
watch watch for object events
|
||||
policy manage anonymous access to objects
|
||||
tag manage tags for an object
|
||||
admin manage MinIO servers
|
||||
session manage saved sessions for cp command
|
||||
config manage mc configuration file
|
||||
update check for a new software update
|
||||
mv move objects
|
||||
ls list buckets and objects
|
||||
mb make a bucket
|
||||
rb remove a bucket
|
||||
cp copy objects
|
||||
mirror synchronize object(s) to a remote site
|
||||
cat display object contents
|
||||
head display first 'n' lines of an object
|
||||
pipe stream STDIN to an object
|
||||
share generate URL for temporary access to an object
|
||||
find search for objects
|
||||
sql run sql queries on objects
|
||||
stat show object metadata
|
||||
mv move objects
|
||||
tree list buckets and objects in a tree format
|
||||
du summarize disk usage recursively
|
||||
lock set and get object lock configuration
|
||||
retention set retention for object(s)
|
||||
legalhold set legal hold for object(s)
|
||||
diff list differences in object name, size, and date between two buckets
|
||||
rm remove objects
|
||||
event configure object notifications
|
||||
watch listen for object notification events
|
||||
policy manage anonymous access to buckets and objects
|
||||
tag manage tags for an object
|
||||
admin manage MinIO servers
|
||||
config configure MinIO client
|
||||
update update mc to latest release
|
||||
```
|
||||
|
||||
## 1. Download MinIO Client
|
||||
@@ -153,20 +153,20 @@ mc config host add gcs https://storage.googleapis.com BKIKJAA5BMMU2RHO6IBB V8f1
|
||||
|
||||
### Example - Specify keys using standard input
|
||||
|
||||
1. Prompt
|
||||
#### Prompt
|
||||
|
||||
```
|
||||
mc config host add minio http://192.168.1.51 --api S3v4
|
||||
Enter Access Key: BKIKJAA5BMMU2RHO6IBB
|
||||
Enter Secret Key: V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12
|
||||
```
|
||||
```
|
||||
mc config host add minio http://192.168.1.51 --api S3v4
|
||||
Enter Access Key: BKIKJAA5BMMU2RHO6IBB
|
||||
Enter Secret Key: V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12
|
||||
```
|
||||
|
||||
2. Pipe
|
||||
#### Pipe from STDIN
|
||||
|
||||
```
|
||||
echo -e "BKIKJAA5BMMU2RHO6IBB\nV7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12" | \
|
||||
mc config host add minio http://192.168.1.51 --api S3v4
|
||||
```
|
||||
```
|
||||
echo -e "BKIKJAA5BMMU2RHO6IBB\nV7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12" | \
|
||||
mc config host add minio http://192.168.1.51 --api S3v4
|
||||
```
|
||||
|
||||
### Specify host configuration through environment variable
|
||||
```
|
||||
@@ -277,24 +277,24 @@ Display the current version of `mc` installed
|
||||
|
||||
```
|
||||
mc --version
|
||||
mc version RELEASE.2016-04-01T00-22-11Z
|
||||
mc version RELEASE.2020-04-25T00-43-23Z
|
||||
```
|
||||
|
||||
## 7. Commands
|
||||
|
||||
| | | | |
|
||||
|:---------------------------------------------------------|:--------------------------------------------------------------|:------------------------------------------------------------------------------------|-----------------------------------------|
|
||||
| [**ls** - List buckets and objects](#ls) | [**tree** - List buckets and objects in a tree format](#tree) | [**mb** - Make a bucket](#mb) | [**cat** - Concatenate an object](#cat) |
|
||||
| [**cp** - Copy objects](#cp) | [**rb** - Remove a bucket](#rb) | [**pipe** - Pipe to an object](#pipe) | |
|
||||
| [**share** - Share access](#share) | [**rm** - Remove objects](#rm) | [**find** - Find files and objects](#find) | |
|
||||
| [**diff** - Diff buckets](#diff) | [**mirror** - Mirror buckets](#mirror) | [**session** - Manage saved sessions](#session) | |
|
||||
| [**config** - Manage config file](#config) | [**policy** - Set public policy on bucket or prefix](#policy) | [**event** - Manage events on your buckets](#event) | |
|
||||
| [**update** - Manage software updates](#update) | [**watch** - Watch for events](#watch) | [**stat** - Stat contents of objects and folders](#stat) | |
|
||||
| [**head** - Display first 'n' lines of an object](#head) | [**lock** - set and get object lock configuration](#lock) | [**retention** - set object retention for objects with a given prefix](#retention) | |
|
||||
| [**mv** - Move objects](#mv) | [**sql** - Run sql queries on objects](#sql) | [**legalhold** - set object legal hold for objects with a given prefix](#legalhold) | |
|
||||
| | | | |
|
||||
|:----------------------------------------------------------------------------------------|:---------------------------------------------------------------|:-----------------------------------------------------------|-------------------------------------------|
|
||||
| [**ls** - list buckets and objects](#ls) | [**tree** - list buckets and objects in a tree format](#tree) | [**mb** - make a bucket](#mb) | [**cat** - display object contents](#cat) |
|
||||
| [**cp** - copy objects](#cp) | [**rb** - remove a bucket](#rb) | [**pipe** - stream STDIN to an object](#pipe) | |
|
||||
| [**share** - generate URL for temporary access to an object](#share) | [**rm** - remove objects](#rm) | [**find** - find files and objects](#find) | |
|
||||
| [**diff** - list differences in object name, size, and date between two buckets](#diff) | [**mirror** - synchronize object(s) to a remote site](#mirror) | | |
|
||||
| [**config** - manage config file](#config) | [**policy** - set public policy on bucket or prefix](#policy) | [**event** - manage events on your buckets](#event) | |
|
||||
| [**update** - manage software updates](#update) | [**watch** - watch for events](#watch) | [**stat** - stat contents of objects and folders](#stat) | |
|
||||
| [**head** - display first 'n' lines of an object](#head) | [**lock** - set and get object lock configuration](#lock) | [**retention** - set retention for object(s)](#retention) | |
|
||||
| [**mv** - move objects](#mv) | [**sql** - run sql queries on objects](#sql) | [**legalhold** - set legal hold for object(s)](#legalhold) | |
|
||||
|
||||
|
||||
### Command `ls` - List Objects
|
||||
### Command `ls`
|
||||
`ls` command lists files, buckets and objects. Use `--incomplete` flag to list partially copied content.
|
||||
|
||||
```
|
||||
@@ -319,7 +319,7 @@ mc ls play
|
||||
```
|
||||
|
||||
<a name="tree"></a>
|
||||
### Command `tree` - List buckets and directories in a tree format
|
||||
### Command `tree`
|
||||
|
||||
`tree` command lists buckets and directories in a tree format. Use `--files` flag to include files/objects in listing.
|
||||
|
||||
@@ -347,7 +347,7 @@ play/test-bucket/
|
||||
|
||||
|
||||
<a name="mb"></a>
|
||||
### Command `mb` - Make a Bucket
|
||||
### Command `mb`
|
||||
`mb` command creates a new bucket on an object storage. On a filesystem, it behaves like `mkdir -p` command. Bucket is equivalent of a drive or mount point in filesystems and should not be treated as folders. MinIO does not place any limits on the number of buckets created per user.
|
||||
On Amazon S3, each account is limited to 100 buckets. Please refer to [Buckets Restrictions and Limitations on S3](http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html) for more information.
|
||||
|
||||
@@ -380,7 +380,7 @@ Bucket created successfully ‘s3/mybucket’.
|
||||
```
|
||||
|
||||
<a name="rb"></a>
|
||||
### Command `rb` - Remove a Bucket
|
||||
### Command `rb`
|
||||
`rb` command removes a bucket and all its contents on an object storage. On a filesystem, it behaves like `rmdir` command.
|
||||
|
||||
Note that when a bucket is removed all policies associated with the bucket will also be removed. If you would like to just
|
||||
@@ -406,7 +406,7 @@ Bucket removed successfully ‘play/mybucket’.
|
||||
```
|
||||
|
||||
<a name="cat"></a>
|
||||
### Command `cat` - Concatenate Objects
|
||||
### Command `cat`
|
||||
`cat` command concatenates contents of a file or object to another. You may also use it to simply display the contents to stdout
|
||||
|
||||
```
|
||||
@@ -443,7 +443,7 @@ Hello MinIO!!
|
||||
```
|
||||
|
||||
<a name="sql"></a>
|
||||
### Command `sql` - Run sql queries on objects
|
||||
### Command `sql`
|
||||
`sql` run sql queries on objects.
|
||||
|
||||
```
|
||||
@@ -528,7 +528,7 @@ mc sql --encrypt-key "myminio/iot-devices=32byteslongsecretkeymustbegiven1" \
|
||||
For more query examples refer to official AWS S3 documentation [here](https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectSELECTContent.html#RESTObjectSELECTContent-responses-examples)
|
||||
|
||||
<a name="head"></a>
|
||||
### Command `head` - Display few lines of object
|
||||
### Command `head`
|
||||
`head` display first 'n' lines of an object
|
||||
|
||||
```
|
||||
@@ -559,7 +559,7 @@ Hello!!
|
||||
```
|
||||
|
||||
<a name="lock"></a>
|
||||
### Command `lock` - set and get object lock configuration
|
||||
### Command `lock`
|
||||
`lock` sets and gets object lock configuration
|
||||
|
||||
```
|
||||
@@ -594,11 +594,11 @@ COMPLIANCE mode is enabled for 30d
|
||||
|
||||
```
|
||||
mc lock --clear myminio/mybucket
|
||||
No object lock configuration is enabled
|
||||
Object lock configuration cleared successfully
|
||||
```
|
||||
|
||||
<a name="retention"></a>
|
||||
### Command `retention` - set object retention for objects with a given prefix
|
||||
### Command `retention`
|
||||
`retention` sets object retention for objects with a given prefix
|
||||
|
||||
```
|
||||
@@ -615,7 +615,7 @@ FLAGS:
|
||||
*Example: Set governance for 30 days for object `prefix` on bucket `mybucket`*
|
||||
|
||||
```
|
||||
mc retention myminio/mybucket/prefix governance 30d -r
|
||||
mc retention myminio/mybucket/prefix governance 30d -r
|
||||
Object retention successfully set for objects with prefix `myminio/mybucket/prefix`.
|
||||
|
||||
```
|
||||
@@ -629,7 +629,7 @@ mc: <ERROR> Failed to remove `myminio/mybucket/prefix/comp.csv`. Object is WORM
|
||||
```
|
||||
|
||||
<a name="legalhold"></a>
|
||||
### Command `legalhold` - set object legal hold for objects
|
||||
### Command `legalhold`
|
||||
`legalhold` sets object legal hold for objects
|
||||
|
||||
```
|
||||
@@ -660,7 +660,7 @@ mc: <ERROR> Failed to remove `myminio/mybucket/prefix/test.csv`. Object is WORM
|
||||
```
|
||||
|
||||
<a name="pipe"></a>
|
||||
### Command `pipe` - Pipe to Object
|
||||
### Command `pipe`
|
||||
`pipe` command copies contents of stdin to a target. When no target is specified, it writes to stdout.
|
||||
|
||||
```
|
||||
@@ -685,7 +685,7 @@ mysqldump -u root -p ******* accountsdb | mc pipe s3/sql-backups/backups/account
|
||||
|
||||
|
||||
<a name="cp"></a>
|
||||
### Command `cp` - Copy Objects
|
||||
### Command `cp`
|
||||
`cp` command copies data from one or more sources to a target. All copy operations to object storage are verified with MD5SUM checksums. Interrupted or failed copy operations can be resumed from the point of failure.
|
||||
|
||||
```
|
||||
@@ -766,7 +766,7 @@ myobject.txt: 14 B / 14 B ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
|
||||
```
|
||||
|
||||
<a name="mv"></a>
|
||||
### Command `mv` - Move Objects
|
||||
### Command `mv`
|
||||
`mv` command movies data from one or more sources to a target. All move operations to object storage are verified with MD5SUM checksums. Interrupted or failed move operations can be resumed from the point of failure.
|
||||
|
||||
```
|
||||
@@ -855,7 +855,7 @@ Waiting move operations to complete
|
||||
```
|
||||
|
||||
<a name="rm"></a>
|
||||
### Command `rm` - Remove Objects
|
||||
### Command `rm`
|
||||
Use `rm` command to remove file or object
|
||||
|
||||
```
|
||||
@@ -915,7 +915,7 @@ Removing `myminio/mybucket/dayOld3.txt`.
|
||||
```
|
||||
|
||||
<a name="share"></a>
|
||||
### Command `share` - Share Access
|
||||
### Command `share`
|
||||
`share` command securely grants upload or download access to object storage. This access is only temporary and it is safe to share with remote users and applications. If you want to grant permanent access, you may look at `mc policy` command instead.
|
||||
|
||||
Generated URL has access credentials encoded in it. Any attempt to tamper the URL will invalidate the access. To understand how this mechanism works, please follow [Pre-Signed URL](http://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURL.html) technique.
|
||||
@@ -993,7 +993,7 @@ COMMAND:
|
||||
```
|
||||
|
||||
<a name="mirror"></a>
|
||||
### Command `mirror` - Mirror Buckets
|
||||
### Command `mirror`
|
||||
`mirror` command is similar to `rsync`, except it synchronizes contents between filesystems and object storage.
|
||||
|
||||
```
|
||||
@@ -1035,7 +1035,7 @@ localdir/new.txt: 10 MB / 10 MB ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓
|
||||
```
|
||||
|
||||
<a name="find"></a>
|
||||
### Command `find` - Find files and objects
|
||||
### Command `find`
|
||||
``find`` command finds files which match the given set of parameters. It only lists the contents which match the given set of criteria.
|
||||
|
||||
```
|
||||
@@ -1066,7 +1066,7 @@ mc find s3/bucket --name "*.jpg" --watch --exec "mc cp {} play/bucket"
|
||||
```
|
||||
|
||||
<a name="diff"></a>
|
||||
### Command `diff` - Show Difference
|
||||
### Command `diff`
|
||||
``diff`` command computes the differences between the two directories. It only lists the contents which are missing or which differ in size.
|
||||
|
||||
It *DOES NOT* compare the contents, so it is possible that the objects which are of same name and of the same size, but have difference in contents are not detected. This way, it can perform high speed comparison on large volumes or between sites
|
||||
@@ -1121,7 +1121,7 @@ mc diff minio1/diffbucket minio2/diffbucket --json
|
||||
| differInSecond | 5 | Only in target (SECOND) |
|
||||
|
||||
<a name="watch"></a>
|
||||
### Command `watch` - Watch for files and object storage events.
|
||||
### Command `watch`
|
||||
``watch`` provides a convenient way to watch on various types of event notifications on object
|
||||
storage and filesystem.
|
||||
|
||||
@@ -1157,7 +1157,7 @@ mc watch ~/Photos
|
||||
```
|
||||
|
||||
<a name="event"></a>
|
||||
### Command `event` - Manage bucket event notification.
|
||||
### Command `event`
|
||||
``event`` provides a convenient way to configure various types of event notifications on a bucket. MinIO event notification can be configured to use AMQP, Redis, ElasticSearch, NATS and PostgreSQL services. MinIO configuration provides more details on how these services can be configured.
|
||||
|
||||
```
|
||||
@@ -1202,7 +1202,7 @@ mc event remove play/andoria arn:minio:sqs:us-east-1:1:your-queue
|
||||
```
|
||||
|
||||
<a name="policy"></a>
|
||||
### Command `policy` - Manage bucket policies
|
||||
### Command `policy`
|
||||
Manage anonymous bucket policies to a bucket and its contents
|
||||
|
||||
```
|
||||
@@ -1260,7 +1260,7 @@ Access permission for ‘play/mybucket/myphotos/2020/’ is set to 'none'
|
||||
```
|
||||
|
||||
<a name="tag"></a>
|
||||
### Command `tag` - Manage tags for an object
|
||||
### Command `tag`
|
||||
` tag` command provides a convenient way to set, remove, and list object tags. Tags are defined as key-value pairs.
|
||||
|
||||
|
||||
@@ -1303,11 +1303,11 @@ Tags removed for s3/testbucket/testobject.
|
||||
```
|
||||
|
||||
<a name="admin"></a>
|
||||
### Command `admin` - Manage MinIO servers
|
||||
### Command `admin`
|
||||
Please visit [here](https://docs.min.io/docs/minio-admin-complete-guide) for a more comprehensive admin guide.
|
||||
|
||||
<a name="config"></a>
|
||||
### Command `config` - Manage Config File
|
||||
### Command `config`
|
||||
`config host` command provides a convenient way to manage host entries in your config file `~/.mc/config.json`. It is also OK to edit the config file manually using a text editor.
|
||||
|
||||
```
|
||||
@@ -1346,7 +1346,7 @@ mc config host list
|
||||
```
|
||||
|
||||
<a name="update"></a>
|
||||
### Command `update` - Software Updates
|
||||
### Command `update`
|
||||
Check for new software updates from [https://dl.min.io](https://dl.min.io). Experimental flag checks for unstable experimental releases primarily meant for testing purposes.
|
||||
|
||||
```
|
||||
@@ -1367,7 +1367,7 @@ You are already running the most recent version of ‘mc’.
|
||||
```
|
||||
|
||||
<a name="stat"></a>
|
||||
### Command `stat` - Stat contents of objects and folders
|
||||
### Command `stat`
|
||||
`stat` command displays information on objects (with optional prefix) contained in the specified bucket on an object storage. On a filesystem, it behaves like `stat` command.
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user