@skidelo
Maybe it is better to open an own thread.
If I were you, I would install Nextcloud completely empty, create the users manually, etc. Then I would copy (or mount) the data back into the datadirectory structure, and then re-load the files/directory in Nextcloud database with
(note that I keep my store in a non-standard and detached-storage location. Also note that I’m using nextcloud snap)
The backstory:
I hosed my server by fatfingering a couple of commands as a privileged user. I had to wipe and reinstall the entire OS et al
How I fixed the exact same error username is invalid because it already exists for this user when attempting to create the user on my freshly installed nextcloud:
(note that for the purposes of this walk-through, let’s say the directory is named “theo”)
I went to the datastore where the user directory existed and mv theo theo-restore
I created the new “theo” user in nextcloud, which succeeded this time.
Nextcloud created the new directory automatically in the data store. When I checked it, it was just a normal empty directory. So, I copied the contents from the old directory to the newly created directory in its entirety. cp -ap theo-restore/* theo/
Nextcloud happily imported the state of the files in the directory all by itself.
When all is done and validated, rm -rf theo-restore