[SOLVED] Migration from a server with faulty harddrive using docker

EDIT: Found solution, see below question.


So my nextcloud server had segmentation fault issues and I was not able to do a proper migration. Instead, I need to make use of my backup data, which does not include the snapshot of the database as described in the docs, but has only the folder structure. When copying everything over to a new server, there were many issues, one of them being that the permissions were not set correctly.

Do you have a resource or a tutorial what steps I need to take to recover my server from the folder structure alone (i.e. app, data, database)?

I’m using docker-compose to set up the server, so following the docker-compose.yml file it should be fairly easy to reproduce my former configuration.

Nextcloud version: 26
Operating system and version: docker-compose

Steps to replicate it:

  1. Copy all the data from one server
  2. Try to start the container from another server, including all the data
  3. Face permissions errors

Please tell me if you need more details.


So Indeed, I managed to recover my nextcloud server fully using the answer of Factor Three, i.e. the third answer, of this stackoverflow post:

However, some steps are missing in the answer, which I want to provide now. First, it’s important to get the container with the same version as before (this is a no-brainer, but I only realized it late). Then, the main ingredient are the permissions, as outlined in the stackoverflow answer. To this end, first clone a new nextcloud entity with the same docker-compose.yml but without the data you want to insert. This is only a dry-run to understand what permissions you need. Create an dummy admin in the browser as you did for the old server in order to populate the database. Afterwards you can check the permissions of your directories with ls -la. Then, use (with sudo if you did not unlock non-sudo docker)

docker exec -u www-data -it nextcloud-app /bin/bash

with this command you go into the virtual container (use the correct container name) with the user www-data. Then, you can use ls -la to understand the permissions, users and groups of the directories you mounted. Do the same for the mysql container (or whatever database you use). Note that there is a user mysql which does not exist in the non-virtual directory and is displayed with user 999 if there outside of the virtual environment (which you cannot set- as far as I understand, it’s set automatically when you use a user in docker which does not exist outside). After you have noted down all permissions etc., you shut down the server and replace the directories with the ones you have rescued from the old server. Put the server into maintenance mode with the config.php file. Then, make sure to implement all permissions (chmod) and user rights (chown) on your server level. After this, you can start the server again, in order to go into the virtual environment of the container.

Inside of the virtual containers, change the permissions and user rights as you have found out earlier (with the -u root option in order to be able to change everything). Then, exit the bash and shut down the server. Then start it again. Now, it should work (at least it did for me). Good luck!

there are lot of discussions regarding such issues on this forum.

you can not “recover” using only the folder structure. You end up with a fresh install where you import data. you can start fresh docker setup, re-create your users, restore the files from the old server and run occ files:scan to make the server aware of the files. this is maybe the best you can do without DB backup…

Your answer is wrong. I was able to recover everything using only the folder structure.

Please don’t post unqualified statements! It is NOT possible to recover the server using the storage only. you might be close if if you only use file storage but even than tags, comments, shares and other metadata which lives in the database are lost.

dear wwe, using the method above the database is recovered as well, since I also copy the database folder and apply the permissions. Hence, all tags, comments, shares and the other metadata is not lost, everything is there. I can ensure you that all the metadata is recovered from the method I describe above, otherwise I would have tried a different method.