# Reinstall using existing data-dir and user names

**URL:** <https://help.nextcloud.com/t/reinstall-using-existing-data-dir-and-user-names/102932>\
**Category:** ℹ️ Support\
**Created:** [January 1, 2021, 10:02pm UTC](https://help.nextcloud.com/t/reinstall-using-existing-data-dir-and-user-names/102932 "2021-01-01T22:02:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chuckn246](https://help.nextcloud.com/user_avatar/help.nextcloud.com/chuckn246/32/7404_2.png) [@chuckn246](https://help.nextcloud.com/u/chuckn246)\
**Post date:** [January 1, 2021, 10:02pm UTC](https://help.nextcloud.com/t/reinstall-using-existing-data-dir-and-user-names/102932/1 "2021-01-01T22:02:09Z")

</div>

I am planning on migrating my Nextcloud installation to a new VM and came across an issue while testing the installation.

By setting `--data-dir` to an existing nfs share and using the same username as the original installation, it failed with the following error:

```ini
Username is invalid because files already exist for this user

```

I think it may be related to this change: [Prevent creating users with existing files by nickvergessen · Pull Request #18130 · nextcloud/server · GitHub](https://github.com/nextcloud/server/pull/18130)

Is there a recommended procedure for using the existing data with the same usernames in the new install?

Full command used to install:

```bash
php occ maintenance:install --database mysql --database-name my_db_name \
    --database-user my_db_user --database-pass my_db_pass --admin-user admin_user \
    --admin-pass admin_pass --data-dir /path/to/nfs/share

```

---

<div class="post-metadata">

**Author:** ![skidelo](https://help.nextcloud.com/user_avatar/help.nextcloud.com/skidelo/32/5790_2.png) [@skidelo](https://help.nextcloud.com/u/skidelo)\
**Post date:** [November 2, 2022, 9:28pm UTC](https://help.nextcloud.com/t/reinstall-using-existing-data-dir-and-user-names/102932/2 "2022-11-02T21:28:26Z")

</div>

+1. I’m running into the same problem. Did you ever find a solution @chuckn246 ?

---

<div class="post-metadata">

**Author:** ![devnull](https://help.nextcloud.com/user_avatar/help.nextcloud.com/devnull/32/27793_2.png) [@devnull](https://help.nextcloud.com/u/devnull)\
**Post date:** [November 3, 2022, 10:31am UTC](https://help.nextcloud.com/t/reinstall-using-existing-data-dir-and-user-names/102932/3 "2022-11-03T10:31:25Z")

</div>

@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

`sudo -u www-data /path/to/nextcloud/occ files:scan --all`  
[documentation](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html#file-operations)

---

<div class="post-metadata">

**Author:** ![cloaked1](https://help.nextcloud.com/user_avatar/help.nextcloud.com/cloaked1/32/54784_2.png) [@cloaked1](https://help.nextcloud.com/u/cloaked1)\
**Post date:** [October 25, 2023, 1:57am UTC](https://help.nextcloud.com/t/reinstall-using-existing-data-dir-and-user-names/102932/4 "2023-10-25T01:57:26Z")

</div>

I accomplished this by doing the following:

(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”)

1. I went to the datastore where the user directory existed and `mv theo theo-restore`
2. I created the new “theo” user in nextcloud, which succeeded this time.
3. 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`

---

<div class="post-metadata">

**Author:** ![herc001](https://help.nextcloud.com/letter_avatar/herc001/32/5_5575768a8748004e209b776fc1b2916d.png) [@herc001](https://help.nextcloud.com/u/herc001)\
**Post date:** [September 15, 2024, 7:03am UTC](https://help.nextcloud.com/t/reinstall-using-existing-data-dir-and-user-names/102932/5 "2024-09-15T07:03:21Z")

</div>

@cloaked1 Your steps worked for me as to getting my new install of Nextcloud onto a new server. The old server fried but my Raid drives were thankfully intact. I had to reinstall the new OS onto a new drive since that was the cause of all my issues.

I got all the way through the installation this time. I did steps 1-3. I verified that they did copy over correctly via the terminal. Everything was there but I can’t see them but not when I login to the dashboard. Am I missing something? Is there a utility I need to run for NC to start displaying my files?

I have 4 other users I need to setup. I don’t want to do the above procedures until I sort out the first one.

---

<div class="post-metadata">

**Author:** ![system](https://help.nextcloud.com/user_avatar/help.nextcloud.com/system/32/29333_2.png) [@system](https://help.nextcloud.com/u/system)\
**Post date:** [December 14, 2024, 7:03am UTC](https://help.nextcloud.com/t/reinstall-using-existing-data-dir-and-user-names/102932/6 "2024-12-14T07:03:51Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
