[lxd] lxc copy --refresh to remote error: can't rename because file exists

I’ve used this command on my backup server to make the initial backup and it works.

/snap/bin/lxc copy T620:vaultwarden bkp-vaultwarden --refresh -s machines

when I rerun the command to really refresh the backup I get the following error.

Error: Failed instance creation: Error transferring instance data: Failed creating instance on target: rename /var/snap/lxd/common/lxd/storage-pools/machines/containers/migration.2682469171/snap0/snap0 /var/snap/lxd/common/lxd/storage-pools/machines/containers-snapshots/bkp-vaultwarden/snap0: file exists

snap0 exists because it should exist so I don’t understand why the refresh fails.

Both servers are running lxd 5.11

Any ideas @monstermunchkin ? Could this be related to optimized refresh?

I’m getting the same issue, or at least a very close one.

I have two servers, lets call them source and backup with 18 containers on.
Every night source updates backup with a copy --refresh, been working for years.

Yesterday one of the storage pools on source started to get close to being full so I stopped two of the containers and moved them into the other storage storage pool on the same server under new names, renamed them back to the original names and started them again.

That night the refresh of the two containers that were moved on source both failed, the rest were fine.

So I went to the backup machine, removed all traces of both the containers and their incomplete migration folders, making sure they were also removed from LXD SQL and the btrfs filesystem, both in the containers and containers-snapshots folders. Effectively making sure there was no trace of these containers on backup.

I then created fresh copies of the two containers on backup from source which worked…
lxc copy container backup:container --storage=default --mode=push
Which worked…

However whenever I try a refresh of those containers…
lxc copy container backup:container --refresh --storage=default --mode=push
It runs for a considerable amount of time transferring data into the migration folder then errors with…
Error: Failed instance migration: Failed migration on source: Error from migration control target: Failed creating instance on target: rename /var/snap/lxd/
common/lxd/storage-pools/default/containers/migration.844538622/2024-09-01-monthly/2024-09-01-monthly /var/snap/lxd/common/lxd/storage-pools/default/contain
ers-snapshots/container/2024-09-01-monthly: file exists

…which of course it does as this is a refresh.

I am now in a state where the containers exist on both machines but I cannot refresh them.

I have tried restarts and recopying multiple times, same error every time.

Both machines running:
Ubuntu 22.04.4 LTS
snap: lxd 6.1-78a3d8f

The next thing I am going to try is fully updating apt on both machines and trying again.

For others who come across this issue, I managed to solve it in my case by deleting all the snapshots at the source. It appears there may be a refresh issue with snapshots which have moved storage volumes?