|
|
@ -9,6 +9,7 @@ import ( |
|
|
|
"github.com/chrislusf/seaweedfs/weed/util" |
|
|
|
"io" |
|
|
|
"path/filepath" |
|
|
|
"regexp" |
|
|
|
) |
|
|
|
|
|
|
|
func init() { |
|
|
@ -43,6 +44,7 @@ func (c *commandRemoteMountBuckets) Do(args []string, commandEnv *CommandEnv, wr |
|
|
|
|
|
|
|
remote := remoteMountBucketsCommand.String("remote", "", "a already configured storage name") |
|
|
|
bucketPattern := remoteMountBucketsCommand.String("bucketPattern", "", "match existing bucket name with wildcard characters '*' and '?'") |
|
|
|
trimBucketSuffix := remoteMountBucketsCommand.Bool("trimBucketSuffix", false, "remote suffix auto generated by 'weed filer.remote.sync'") |
|
|
|
apply := remoteMountBucketsCommand.Bool("apply", false, "apply the mount for listed buckets") |
|
|
|
|
|
|
|
if err = remoteMountBucketsCommand.Parse(args); err != nil { |
|
|
@ -76,6 +78,8 @@ func (c *commandRemoteMountBuckets) Do(args []string, commandEnv *CommandEnv, wr |
|
|
|
return fmt.Errorf("read filer buckets path: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
hasSuffixPattern, _ := regexp.Compile(".+-[0-9][0-9][0-9][0-9]") |
|
|
|
|
|
|
|
for _, bucket := range buckets { |
|
|
|
if *bucketPattern != "" { |
|
|
|
if matched, _ := filepath.Match(*bucketPattern, bucket.Name); !matched { |
|
|
@ -84,9 +88,16 @@ func (c *commandRemoteMountBuckets) Do(args []string, commandEnv *CommandEnv, wr |
|
|
|
} |
|
|
|
|
|
|
|
fmt.Fprintf(writer, "bucket %s\n", bucket.Name) |
|
|
|
localBucketName := bucket.Name |
|
|
|
if *trimBucketSuffix { |
|
|
|
if hasSuffixPattern.MatchString(localBucketName) { |
|
|
|
localBucketName = localBucketName[:len(localBucketName)-5] |
|
|
|
fmt.Fprintf(writer, " mount bucket %s as %s\n", bucket.Name, localBucketName) |
|
|
|
} |
|
|
|
} |
|
|
|
if *apply { |
|
|
|
|
|
|
|
dir := util.FullPath(fillerBucketsPath).Child(bucket.Name) |
|
|
|
dir := util.FullPath(fillerBucketsPath).Child(localBucketName) |
|
|
|
remoteStorageLocation := &remote_pb.RemoteStorageLocation{ |
|
|
|
Name: *remote, |
|
|
|
Bucket: bucket.Name, |
|
|
|