github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/docs/bucket/replication/README.md (about) 1 # Bucket Replication Guide [![slack](https://slack.min.io/slack?type=svg)](https://slack.min.io) [![Docker Pulls](https://img.shields.io/docker/pulls/minio/minio.svg?maxAge=604800)](https://hub.docker.com/r/minio/minio/) 2 3 Bucket replication is designed to replicate selected objects in a bucket to a destination bucket. 4 5 The contents of this page have been migrated to the new [MinIO Documentation: Bucket Replication](https://min.io/docs/minio/linux/administration/bucket-replication.html) page. The [Bucket Replication](https://min.io/docs/minio/linux/administration/bucket-replication/bucket-replication-requirements.html) page references dedicated tutorials for configuring one-way "Active-Passive" and two-way "Active-Active" bucket replication. 6 7 To replicate objects in a bucket to a destination bucket on a target site either in the same cluster or a different cluster, start by enabling [versioning](https://min.io/docs/minio/linux/administration/object-management/object-versioning.html) for both source and destination buckets. Finally, the target site and the destination bucket need to be configured on the source MinIO server. 8 9 ## Highlights 10 11 - Supports source and destination buckets to have the same name unlike AWS S3, addresses variety of usecases such as *Splunk*, *Veeam* site to site DR. 12 - Supports object locking/retention across source and destination buckets natively out of the box, unlike AWS S3. 13 - Simpler implementation than [AWS S3 Bucket Replication Config](https://docs.aws.amazon.com/AmazonS3/latest/dev/replication-add-config.html) with requirements such as IAM Role, AccessControlTranslation, Metrics and SourceSelectionCriteria are not needed with MinIO. 14 - Active-Active replication 15 - Multi destination replication 16 17 ## How to use? 18 19 Ensure that versioning is enabled on the source and target buckets with `mc version` command. If object locking is required, the buckets should have been created with `mc mb --with-lock` 20 21 The user setting up replication needs *s3:GetReplicationConfiguration* and *s3:GetBucketVersioning* permission on the source cluster. We do not recommend running root credentials/super admin with replication, instead create a dedicated user. The access credentials used at the destination requires *s3:ReplicateObject* permission. 22 23 The following minimal permission policy is needed by admin user setting up replication on the `source`: 24 25 ``` 26 { 27 "Version": "2012-10-17", 28 "Statement": [ 29 { 30 "Action": [ 31 "admin:SetBucketTarget", 32 "admin:GetBucketTarget" 33 ], 34 "Effect": "Allow", 35 "Sid": "" 36 }, 37 { 38 "Effect": "Allow", 39 "Action": [ 40 "s3:GetReplicationConfiguration", 41 "s3:PutReplicationConfiguration", 42 "s3:ListBucket", 43 "s3:ListBucketMultipartUploads", 44 "s3:GetBucketLocation", 45 "s3:GetBucketVersioning" 46 ], 47 "Resource": [ 48 "arn:aws:s3:::srcbucket" 49 ] 50 } 51 ] 52 } 53 ``` 54 55 The access key provided for the replication *target* cluster should have these minimal permissions: 56 57 ``` 58 { 59 "Version": "2012-10-17", 60 "Statement": [ 61 { 62 "Effect": "Allow", 63 "Action": [ 64 "s3:GetReplicationConfiguration", 65 "s3:ListBucket", 66 "s3:ListBucketMultipartUploads", 67 "s3:GetBucketLocation", 68 "s3:GetBucketVersioning", 69 "s3:GetBucketObjectLockConfiguration" 70 ], 71 "Resource": [ 72 "arn:aws:s3:::destbucket" 73 ] 74 }, 75 { 76 "Effect": "Allow", 77 "Action": [ 78 "s3:GetReplicationConfiguration", 79 "s3:ReplicateTags", 80 "s3:AbortMultipartUpload", 81 "s3:GetObject", 82 "s3:GetObjectVersion", 83 "s3:GetObjectVersionTagging", 84 "s3:PutObject", 85 "s3:DeleteObject", 86 "s3:ReplicateObject", 87 "s3:ReplicateDelete" 88 ], 89 "Resource": [ 90 "arn:aws:s3:::destbucket/*" 91 ] 92 } 93 ] 94 } 95 ``` 96 97 Please note that the permissions required by the admin user on the target cluster can be more fine grained to exclude permissions like "s3:ReplicateDelete", "s3:GetBucketObjectLockConfiguration" etc depending on whether delete replication rules are set up or if object locking is disabled on `destbucket`. The above policies assume that replication of objects, tags and delete marker replication are all enabled on object lock enabled buckets. A sample script to setup replication is provided [here](https://github.com/minio/minio/blob/master/docs/bucket/replication/setup_replication.sh) 98 99 To set up replication from a source bucket `srcbucket` on myminio cluster to a bucket `destbucket` on the target minio cluster with endpoint https://replica-endpoint:9000, use: 100 ``` 101 mc replicate add myminio/srcbucket --priority 1 --remote-bucket https://accessKey:secretKey@replica-endpoint:9000/destbucket 102 Replication configuration applied successfully to myminio/srcbucket. 103 ``` 104 Internally, this creates an ARN for the remote target associating the remote bucket as a replication target to the srcbucket on myminio.By default, if --replicate flag is not specified, replication of delete marker, permanent deletes, existing object replication and replica modification sync are all enabled. If you are using older mc versions, the ARN needs to be generated as a separate step before adding a replication rule. 105 106 > NOTE: If you are using a mc version below `RELEASE.2022-12-24T15-21-38Z`, the --remote-bucket flag needs an ARN generated by `mc admin bucket remote add` command. For mc versions RELEASE.2021-09-02T09-21-27Z and older, the remote target ARN needs to be passed in the --arn flag and actual remote bucket name in --remote-bucket flag of `mc replicate add`. For example, in older releases of mc replication configuration used to be added with: 107 108 ``` 109 mc admin bucket remote add myminio/srcbucket https://accessKey:secretKey@replica-endpoint:9000/destbucket --service replication --region us-east-1 110 Remote ARN = 'arn:minio:replication:us-east-1:c5be6b16-769d-432a-9ef1-4567081f3566:destbucket' 111 112 mc replicate add myminio/srcbucket/Tax --priority 1 --remote-bucket destbucket --remote-bucket "arn:minio:replication:us-east-1:c5be6b16-769d-432a-9ef1-4567081f3566:destbucket" --tags "Year=2019&Company=AcmeCorp" --storage-class "STANDARD" --replicate "delete,delete-marker" 113 Replication configuration applied successfully to myminio/srcbucket. 114 ``` 115 116 The replication configuration generated has the following format and can be exported with `mc replicate export` command: 117 118 ```json 119 { 120 "Role" :"", 121 "Rules": [ 122 { 123 "Status": "Enabled", 124 "Priority": 1, 125 "DeleteMarkerReplication": { "Status": "Disabled" }, 126 "DeleteReplication": { "Status": "Disabled" }, 127 "Filter" : { 128 "And": { 129 "Prefix": "Tax", 130 "Tags": [ 131 { 132 "Key": "Year", 133 "Value": "2019" 134 }, 135 { 136 "Key": "Company", 137 "Value": "AcmeCorp" 138 } 139 ] 140 } 141 }, 142 "Destination": { 143 "Bucket": "arn:minio:replication:us-east-1:c5be6b16-769d-432a-9ef1-4567081f3566:destbucket", 144 "StorageClass": "STANDARD" 145 }, 146 "SourceSelectionCriteria": { 147 "ReplicaModifications": { 148 "Status": "Enabled" 149 } 150 } 151 } 152 ] 153 } 154 ``` 155 156 The replication configuration follows [AWS S3 Spec](https://docs.aws.amazon.com/AmazonS3/latest/dev/replication-add-config.html). Any objects uploaded to the source bucket that meet replication criteria will now be automatically replicated by the MinIO server to the remote destination bucket. Replication can be disabled at any time by disabling specific rules in the configuration or deleting the replication configuration entirely. 157 158 When object locking is used in conjunction with replication, both source and destination buckets needs to have [object locking](https://min.io/docs/minio/linux/administration/object-management/object-retention.html) enabled. Similarly objects encrypted on the server side, will be replicated if destination also supports encryption. 159 160 Replication status can be seen in the metadata on the source and destination objects. On the source side, the `X-Amz-Replication-Status` changes from `PENDING` to `COMPLETED` or `FAILED` after replication attempt either succeeded or failed respectively. On the destination side, a `X-Amz-Replication-Status` status of `REPLICA` indicates that the object was replicated successfully. Any replication failures are automatically re-attempted during a periodic disk scanner cycle. 161 162 To perform bi-directional replication, repeat the above process on the target site - this time setting the source bucket as the replication target. It is recommended that replication be run in a system with at least two CPU's available to the process, so that replication can run in its own thread. 163 164 ![put](https://raw.githubusercontent.com/minio/minio/master/docs/bucket/replication/PUT_bucket_replication.png) 165 166 ![head](https://raw.githubusercontent.com/minio/minio/master/docs/bucket/replication/HEAD_bucket_replication.png) 167 168 ## Replica Modification sync 169 170 If bi-directional replication is set up between two clusters, any metadata update on the REPLICA object is by default reflected back in the source object when `ReplicaModifications` status in the `SourceSelectionCriteria` is `Enabled`. In MinIO, this is enabled by default. If a metadata update is performed on the "REPLICA" object, its `X-Amz-Replication-Status` will change from `PENDING` to `COMPLETE` or `FAILED`, and the source object version will show `X-Amz-Replication-Status` of `REPLICA` once the replication operation is complete. 171 172 The replication configuration in use on a bucket can be viewed using the `mc replicate export alias/bucket` command. 173 174 To disable replica metadata modification syncing, use `mc replicate edit` with the --replicate flag. 175 176 ``` 177 mc replicate edit alias/bucket --id xyz.id --replicate "delete,delete-marker" 178 ``` 179 180 To re-enable replica metadata modification syncing, 181 182 ``` 183 mc replicate edit alias/bucket --id xyz.id --replicate "delete,delete-marker,replica-metadata-sync" 184 ``` 185 186 ## MinIO Extension 187 188 ### Replicating Deletes 189 190 Delete marker replication is allowed in [AWS V1 Configuration](https://aws.amazon.com/blogs/storage/managing-delete-marker-replication-in-amazon-s3/) but not in V2 configuration. The MinIO implementation above is based on V2 configuration, however it has been extended to allow both DeleteMarker replication and replication of versioned deletes with the `DeleteMarkerReplication` and `DeleteReplication` fields in the replication configuration above. By default, this is set to `Disabled` unless the user specifies it while adding a replication rule. 191 192 When an object is deleted from the source bucket, the corresponding replica version will be marked deleted if delete marker replication is enabled in the replication configuration. Replication of deletes that specify a version id (a.k.a hard deletes) can be enabled by setting the `DeleteReplication` status to enabled in the replication configuration. This is a MinIO specific extension that can be enabled using the `mc replicate add` or `mc replicate edit` command with the --replicate "delete" flag. 193 194 Note that due to this extension behavior, AWS SDK's may not support the extension functionality pertaining to replicating versioned deletes. 195 196 Note that just like with [AWS](https://docs.aws.amazon.com/AmazonS3/latest/userguide/delete-marker-replication.html), Delete marker replication is disallowed in MinIO when the replication rule has tags. 197 198 To add a replication rule allowing both delete marker replication, versioned delete replication or both specify the --replicate flag with comma separated values as in the example below. 199 200 Additional permission of "s3:ReplicateDelete" action would need to be specified on the access key configured for the target cluster if Delete Marker replication or versioned delete replication is enabled. 201 202 ``` 203 mc replicate add myminio/srcbucket/Tax --priority 1 --remote-bucket `remote-target` --tags "Year=2019&Company=AcmeCorp" --storage-class "STANDARD" --replicate "delete,delete-marker" 204 Replication configuration applied successfully to myminio/srcbucket. 205 ``` 206 207 > NOTE: In mc versions `RELEASE.2022-12-24T15-21-38Z` and above `remote-target` should be of the format `https://accessKey:secretKey@replica-endpoint:9000/destbucket` which earlier used to be set during `mc admin bucket remote add`. For older releases, use the arn generated with `mc admin bucket remote add` command - e.g."arn:minio:replication:us-east-1:c5be6b16-769d-432a-9ef1-4567081f3566:destbucket" as the `remote-target`. 208 209 Also note that `mc` version `RELEASE.2021-09-02T09-21-27Z` or older supports only a single remote target per bucket. To take advantage of multiple destination replication, use the latest version of `mc` 210 211 Status of delete marker replication can be viewed by doing a GET/HEAD on the object version - it will return a `X-Minio-Replication-DeleteMarker-Status` header and http response code of `405`. In the case of permanent deletes, if the delete replication is pending or failed to propagate to the target cluster, GET/HEAD will return additional `X-Minio-Replication-Delete-Status` header and a http response code of `405`. 212 213 ![delete](https://raw.githubusercontent.com/minio/minio/master/docs/bucket/replication/DELETE_bucket_replication.png) 214 215 The status of replication can be monitored by configuring event notifications on the source and target buckets using `mc event add`.On the source side, the `s3:PutObject`, `s3:Replication:OperationCompletedReplication` and `s3:Replication:OperationFailedReplication` events show the status of replication in the `X-Amz-Replication-Status` metadata. 216 217 On the target bucket, `s3:PutObject` event shows `X-Amz-Replication-Status` status of `REPLICA` in the metadata. Additional metrics to monitor backlog state for the purpose of bandwidth management and resource allocation are exposed via Prometheus - see <https://github.com/minio/minio/blob/master/docs/metrics/prometheus/list.md> for more details. 218 219 ### Sync/Async Replication 220 221 By default, replication is completed asynchronously. If synchronous replication is desired, set the --sync flag while adding a 222 remote replication target using the `mc admin bucket remote add` command. For mc releases on or after `RELEASE.2022-12-24T15-21-38Z`, the 223 --sync, --health-check and --bandwidth flags can be specified in `mc replicate add|update` command 224 225 ``` 226 mc admin bucket remote add myminio/srcbucket https://accessKey:secretKey@replica-endpoint:9000/destbucket --service replication --region us-east-1 --sync --healthcheck-seconds 100 227 ``` 228 229 ### Existing object replication 230 231 Existing object replication as detailed [here](https://aws.amazon.com/blogs/storage/replicating-existing-objects-between-s3-buckets/) can be enabled by passing `existing-objects` as a value to `--replicate` flag while adding or editing a replication rule. 232 233 Once existing object replication is enabled, all objects or object prefixes that satisfy the replication rules and were created prior to adding replication configuration OR while replication rules were disabled will be synced to the target cluster. Depending on the number of previously existing objects, the existing objects that are now eligible to be replicated will eventually be synced to the target cluster as the scanner schedules them. This may be slower depending on the load on the cluster, latency and size of the namespace. 234 235 In the rare event that target DR site is entirely lost and previously replicated objects to the DR cluster need to be re-replicated, `mc replicate resync start alias/bucket --remote-bucket <arn>` can be used to initiate a reset. This would initiate a re-sync between the two clusters by walking the bucket namespace and replicating eligible objects that satisfy the existing objects replication rule specified in the replication config. The status of the resync operation can be viewed with `mc replicate resync status alias/bucket --remote-bucket <arn>`. 236 237 Note that ExistingObjectReplication needs to be enabled in the config via `mc replicate [add|edit]` by passing `existing-objects` as one of the values to `--replicate` flag. Only those objects meeting replication rules and having existing object replication enabled will be re-synced. 238 239 ### Multi destination replication 240 241 Replication from a source bucket to multiple destination buckets is supported. For each of the targets, repeat the steps to configure a remote target ARN and add replication rules to the source bucket's replication config. 242 243 Note that on the source side, the `X-Amz-Replication-Status` changes from `PENDING` to `COMPLETED` after replication succeeds to each of the targets. On the destination side, a `X-Amz-Replication-Status` status of `REPLICA` indicates that the object was replicated successfully. Any replication failures are automatically re-attempted during a periodic disk scanner cycle. 244 245 ### Interaction with extended Bucket Versioning configuration 246 247 When Bucket Versioning with excluded prefixes are configured objects matching these prefixes are excluded from being versioned and replicated. 248 249 ``` 250 <VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> 251 <Status>Enabled</Status> 252 <ExcludeFolders>true</ExcludeFolders> 253 254 <ExcludedPrefixes> 255 <Prefix>app1-jobs/*/_temporary/</Prefix> 256 </ExcludedPrefixes> 257 <ExcludedPrefixes> 258 <Prefix>app2-jobs/*/_magic/</Prefix> 259 </ExcludedPrefixes> 260 261 <!-- .. up to 10 prefixes in all --> 262 </VersioningConfiguration> 263 ``` 264 265 In the above sample config, objects under prefixes matching any of the `ExcludedPrefixes` glob patterns will neither be versioned nor replicated. 266 267 ### SSE-C Encryption 268 269 MinIO does not support SSE-C encrypted objects on replicated buckets, any application uploading SSE-C encrypted objects will be rejected with an error on replicated buckets. 270 271 #### Rationale 272 273 - SSE-C requires application to remember the keys for all GET/PUT operations, any unfortunate loss of keys would automatically mean the objects cannot be accessed anymore. 274 - SSE-C is hardly adopted by most widely used applications, applications prefer server to manage the keys via SSE-KMS or SSE-S3. 275 - MinIO recommends applications to use SSE-KMS, SSE-S3 for simpler, safer and robust encryption mechanism for replicated buckets. 276 277 ## Explore Further 278 279 - [MinIO Bucket Replication Design](https://github.com/minio/minio/blob/master/docs/bucket/replication/DESIGN.md) 280 - [MinIO Bucket Versioning Implementation](https://min.io/docs/minio/linux/administration/object-management/object-retention.html) 281 - [MinIO Client Quickstart Guide](https://min.io/docs/minio/linux/reference/minio-mc.html#quickstart)