add exclude-storageclass flag for mirror (#4684)
this option exists to skip tiered objects such as - "GLACIER" - "DEEP_ARCHIVE" users can use this option when migrating awss3 -> minio ``` mc mirror --exclude-storageclass GLACIER \ --exclude-storageclass DEEP_ARCHIVE s3/bucket minio/bucket ```
This commit is contained in:
+33
-14
@@ -101,6 +101,10 @@ var (
|
||||
Name: "exclude",
|
||||
Usage: "exclude object(s) that match specified object name pattern",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "exclude-storageclass",
|
||||
Usage: "exclude object(s) that match the specified storage class",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "older-than",
|
||||
Usage: "filter object(s) older than value in duration string (e.g. 7d10h31s)",
|
||||
@@ -581,6 +585,20 @@ func (mj *mirrorJob) watchMirrorEvents(ctx context.Context, events []EventInfo)
|
||||
continue
|
||||
}
|
||||
|
||||
sc, ok := event.UserMetadata["x-amz-storage-class"]
|
||||
if ok {
|
||||
var found bool
|
||||
for _, esc := range mj.opts.excludeStorageClasses {
|
||||
if esc == sc {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
targetPath := urlJoinPath(mj.targetURL, sourceSuffix)
|
||||
|
||||
// newClient needs the unexpanded path, newCLientURL needs the expanded path
|
||||
@@ -890,20 +908,21 @@ func runMirror(ctx context.Context, srcURL, dstURL string, cli *cli.Context, enc
|
||||
isFake := cli.Bool("fake") || cli.Bool("dry-run")
|
||||
|
||||
mopts := mirrorOptions{
|
||||
isFake: isFake,
|
||||
isRemove: isRemove,
|
||||
isOverwrite: isOverwrite,
|
||||
isWatch: isWatch,
|
||||
isMetadata: isMetadata,
|
||||
md5: cli.Bool("md5"),
|
||||
disableMultipart: cli.Bool("disable-multipart"),
|
||||
excludeOptions: cli.StringSlice("exclude"),
|
||||
olderThan: cli.String("older-than"),
|
||||
newerThan: cli.String("newer-than"),
|
||||
storageClass: cli.String("storage-class"),
|
||||
userMetadata: userMetadata,
|
||||
encKeyDB: encKeyDB,
|
||||
activeActive: isWatch,
|
||||
isFake: isFake,
|
||||
isRemove: isRemove,
|
||||
isOverwrite: isOverwrite,
|
||||
isWatch: isWatch,
|
||||
isMetadata: isMetadata,
|
||||
md5: cli.Bool("md5"),
|
||||
disableMultipart: cli.Bool("disable-multipart"),
|
||||
excludeOptions: cli.StringSlice("exclude"),
|
||||
excludeStorageClasses: cli.StringSlice("exclude-storageclass"),
|
||||
olderThan: cli.String("older-than"),
|
||||
newerThan: cli.String("newer-than"),
|
||||
storageClass: cli.String("storage-class"),
|
||||
userMetadata: userMetadata,
|
||||
encKeyDB: encKeyDB,
|
||||
activeActive: isWatch,
|
||||
}
|
||||
|
||||
// Create a new mirror job and execute it
|
||||
|
||||
+21
-8
@@ -147,6 +147,19 @@ func deltaSourceTarget(ctx context.Context, sourceURL, targetURL string, opts mi
|
||||
continue
|
||||
}
|
||||
|
||||
if diffMsg.firstContent != nil {
|
||||
var found bool
|
||||
for _, esc := range opts.excludeStorageClasses {
|
||||
if esc == diffMsg.firstContent.StorageClass {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
switch diffMsg.Diff {
|
||||
case differInNone:
|
||||
// No difference, continue.
|
||||
@@ -203,14 +216,14 @@ func deltaSourceTarget(ctx context.Context, sourceURL, targetURL string, opts mi
|
||||
}
|
||||
|
||||
type mirrorOptions struct {
|
||||
isFake, isOverwrite, activeActive bool
|
||||
isWatch, isRemove, isMetadata bool
|
||||
excludeOptions []string
|
||||
encKeyDB map[string][]prefixSSEPair
|
||||
md5, disableMultipart bool
|
||||
olderThan, newerThan string
|
||||
storageClass string
|
||||
userMetadata map[string]string
|
||||
isFake, isOverwrite, activeActive bool
|
||||
isWatch, isRemove, isMetadata bool
|
||||
excludeOptions, excludeStorageClasses []string
|
||||
encKeyDB map[string][]prefixSSEPair
|
||||
md5, disableMultipart bool
|
||||
olderThan, newerThan string
|
||||
storageClass string
|
||||
userMetadata map[string]string
|
||||
}
|
||||
|
||||
// Prepares urls that need to be copied or removed based on requested options.
|
||||
|
||||
Reference in New Issue
Block a user