My database is gone

I’m using the official Docker image, and docker-compose to configure Nextcloud, reverse Nginx proxy, Letsencrypt, Nextcloud MariaDB instance and so on. Then I had the idea to move it all from my home folder to root’s home folder at /root because I don’t want those files changed easily, but I also want a friend of mine sharing the server to be able to change things. All well and good, but during the process my brain had the idea of “fixing” a “typo”.

So in my docker-compose I had

volumes:
  - nextcloud:/var/www/nextcloud
  - ./nextcloud/config:/var/www/nextcloud/config
  - ./nextcloud/custom_apps:/var/www/nextcloud/custom_apps
  - ./nextcloud/data:/var/www/nextcloud/data
  - ./nextcloud/themes:/var/www/nextcloud/themes
  - /etc/localtime:/etc/localtime:ro

and I changed the first line to

volumes:
  - ./nextcloud:/var/www/nextcloud

Then I realized I probably mucked up my volume by doing that, so I changed it back. I still appear to have all my files, but when I go to the page I get the message that I’m using SQLite and to make an admin account, and install missing apps. So something got messed up with the database, but I don’t think I changed the database volume, though to be honest I don’t remember clearly if I did or not.

My MariaDB config:

volumes:
  - db:/var/lib/mysql
  - ./ncp-mysql.cnf:/etc/mysql/conf.d/ncp-mysql.cnf:ro
  - /etc/localtime:/etc/localtime:ro

I don’t think I did

volumes:
  - ./db:/var/lib/mysql

but maybe I did since it seems like the database is empty? If I start everything and do

docker exec -it nextcloud-mariadb mysql -uroot -p
and switch to the nextcloud database there, it is empty. :frowning:

I only have an old backup from December of the database, I wonder if I should restore that and make it add the missing stuff? All the actual files are still intact, but the database seems gone. What would you do in this situation (except have proper backups, I know, and I’m stupid for not having set up that)?

First thing I would do is put everything back where/how it was and see if it still works that way.

question: do you know the difference between ./db and db and where to look for the files stored in them?

./db would be a folder that does not exist.
./nextcloud is a folder, and that’s the one I told the nextcloud container to use for a brief moment before I realized that no I should not have done that.
db would be a volume, which is from my understanding a virtual space within the container.

nope. all of of them are volumes.

yes: ./db is a folder in your home directory. (i would always recommend absolute paths.)

if you use db the files are store somewhere in /var/lib/docker/volumes/<long-hash>/_data.

may you look if you find there database files?

with docker inspect you can check which bind/volume belongs to which container right now.

in my installation it looks like this:

docker inspect --format '{''{ .Mounts }''}' nextcloud-db
[{bind  /opt/nextcloud/database /var/lib/postgresql/data  rw true rprivate}]

or with a volume

docker inspect --format '{''{ .Mounts }''}' redis
[{volume 37355ccf24571300954a0e35105fcec9160003b0099724ce8f1c96389b8a6215 /var/lib/docker/volumes/37355ccf24571300954a0e35105fcec9160003b0099724ce8f1c96389b8a6215/_data /data local  true }]

so i would check which bind/volume belongs to your running container. and if this file exists also in another place. then i would look at the timestamp and size of this files (and there content if not binary) to decide with on are the correct ones.

if you have a spare server (or second rasbpi) you could start a mysql container there and use the files copied to check if the database is correct. start a container with -v /path/to/copied/files:/var/lib/mysql -v ./ncp-mysql.cnf:/etc/mysql/conf.d/ncp-mysql.cnf:ro

if you are careful and know what you do of course you can start a second mariadb container on your exisiting server.

hope you got the idea.

Yes! I think I found it! Inside
/var/lib/docker/volumes/MYUSERNAME_db/_data/
So it seems since I used to start docker-compose with
sudo docker-compose up -d
from my regular account, it for some reason prepended it with my username there, and now since I started it as the root user it used
/var/lib/docker/volumes/docker_db/_data/ instead.

However I’d like for both me and my friend to be able to do docker-compose up -d
using the same docker-compose file in /root/docker so should I somehow copy over the files from
/var/lib/docker/volumes/MYUSERNAME_db/_data/
to
/var/lib/docker/volumes/docker_db/_data/
then, or what would you recommend on a shared host?

great. hope you can restore your system.

first you should not use ./nextcloud. it’s a relative path.

if you don’t want to move it to nextcloud use /opt/nextcloud/nextcloud or /var/lib/nextcloud. or whatever you prefer. but make it an absolute path.

using nextcloud and therefore inside /var/lib/docker has the advantage that you don’t even have to become root to use docker-compose and change the files. you only have to do it the docker way.

  • add you and your friend to the docker group. so you can both run docker commands without sudo.
  • don’t manipulate the “host files” use the “container files”
    e.g. run: docker exec -it -u www-data nextcloud vim /var/www/netcloud/config/config.php

ok?

Should I make a home folder for the docker user and place everything there then?
One of the reasons I want to use /root is because the docker-compose file contains the database root and user passwords, so it’s sensitive data.

i don’t have a docker user. on my system exists only a docker group.

create where ever you like a folder and chown root:docker ; chmod 0770

/home/docker is as good as /var/local/nextcloud

Okay I did that, though I still get permission denied even though I am in the docker group. I moved everything to /home/docker and the permissions are
drwxrwx--- 6 root docker 4096 Apr 3 19:42 docker/

logged out and in again? as far as I remember group permissions are applied at login.

Oh you’re right, sorry, I forgot about that.

Okay after the trouble persisted I changed my docker-compose file back to how it was before when it comes to paths as well.
I had changed

volumes:
  - nextcloud:/var/www/html
  - ./nextcloud/config:/var/www/html/config
  - ./nextcloud/custom_apps:/var/www/html/custom_apps
  - ./nextcloud/data:/var/www/html/data
  - ./nextcloud/themes:/var/www/html/themes
  - /etc/localtime:/etc/localtime:ro

to

volumes:
  - nextcloud:/var/www/nextcloud
  - ./nextcloud/config:/var/www/nextcloud/config
  - ./nextcloud/custom_apps:/var/www/nextcloud/custom_apps
  - ./nextcloud/data:/var/www/nextcloud/data
  - ./nextcloud/themes:/var/www/nextcloud/themes
  - /etc/localtime:/etc/localtime:ro

so that was part of why it did not work. I changed it back to html, so now I get my database back, though I see this warning:

WARNING: Service “nextcloud” is using volume “/var/www/html” from the previous container. Host mapping “docker_nextcloud” has no effect

What, if anything, should I do about that?

i’m sure there is command line option to tell docker-compose to reuse an old volume. since i’m not using docker compose you may ask google.

in your case the volume nextcloud only contains the files that are any way in the tgz file you download from nextcloud.com and in the docker image.

your config and data is in the other folders data, config, themes and custom_apps. (you should backup this. :wink: )

so what happens if your container starts and /var/www/html is empty? the update script should be triggered.

and since the installed_version is default 0.0.0.0 and the image_version is greater the rsync command in line 91 is executed. but the four config/data folders are excluded.

and i guess you’ll get a running system. but no warranty.
and you have to make sure you start exactly the same image than you used before. because the version is also stored in config.php and the database. and if that doesn’t fit togehter you aren’t successful.