Search code examples
bashminio

Copy contents of a bucket to another bucket in MinIO without copying the bucket itself


I'm using mc to copy some objects in a bucket to another bucket in a MinIO cluster. An example would be this:

$ mc ls minio/media/test
[2023-02-21 23:57:24 +0330] 3.3MiB STANDARD file1.txt
[2023-02-21 23:57:50 +0330] 3.3MiB STANDARD file2.txt

I make another bucket and recursively copy test bucket into it:

$ mc mb minio/media/test2
Bucket created successfully `minio/media/test2`.
$ mc cp -r minio/media/test minio/media/test2
.../media/test/file2.txt: 6.53 MiB / 6.53 MiB ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 52.05MiB/s 0s
$ mc ls minio/media/test2
[2023-02-21 23:59:50 +0330]     0B test/

We see that the directory itself is copied, not just the content of it. I also tried using wildcards, but it gives an error:

$ mc cp -r minio/media/test/* minio/media/test2
mc: <ERROR> Unable to validate source `minio/media/test/*`.

The expected result is this:

$ mc ls minio/media/test2
[2023-02-21 23:57:24 +0330] 3.3MiB STANDARD file1.txt
[2023-02-21 23:57:50 +0330] 3.3MiB STANDARD file2.txt

The reason I'm not simply renaming the bucket is that I'm not actually copying all of its objects, but rather a select chunk of them. How can I do this?


Solution

  • $ mc cp -r minio/media/test/ minio/media/test2
    

    Gives you the result you want. Add a trailing "/" after the source bucket.