diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index 0debd9eb..96b9abf3 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -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 diff --git a/cmd/mirror-url.go b/cmd/mirror-url.go index b0e2d01d..e35a2ed6 100644 --- a/cmd/mirror-url.go +++ b/cmd/mirror-url.go @@ -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.