Bucket replication when it fails due to The remote target already exists - cniackz/public GitHub Wiki

Issue:

$ mc replicate add <ORIGINALALIAS>/replication-bucket \
  --remote-bucket https://<USER>:<PASSWORD>@<URL>/remotebucket \
  --priority 1 \
  --insecure
mc: <ERROR> unable to configure remote target. The remote target already exists.

Introduction:

Above issue can be related to https://github.com/cniackz/public/wiki/Bucket-replication-issue but it also can be something else. In this wiki, we are going to focus in the issue when it partially succeeded.

We have to remember that, replication rule addition is a 2 step process - remote creation and rule addition. If previous attempt partially succeeded, a target was created and should have matched the remote.

Solution:

# First create ALIAS with old mc version
# Then list it:
$ ./mc.RELEASE.2022-02-02T02-03-24Z admin bucket remote ls <ALIAS>/replication-bucket --json
# Check values and get the RemoteARN value
# Then remove it:
$ ./mc.RELEASE.2022-02-02T02-03-24Z admin bucket remote rm <ALIAS>/replication-bucket --arn "<ARNVALUE>"
# Then replicate again and it will work:
mc replicate add <ORIGINALALIAS>/replication-bucket --remote-bucket https://<USER>:<PASSWORD>@<URL>/remotebucket --priority 1 --insecure

Nice to have, or a TODO (Backlog):

We probably can add a validation to force remove the ARN even if replication config is missing in replicate rm --all --force that would put an end to this type of issue

⚠️ **GitHub.com Fallback** ⚠️