How to reinstall Nextcloud or Nextcloud DB without loosing ALL data and configuration

I made the update to 24.0.7 and got errors:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

Trying to solve I have completely destroyed my installation - docker based, with mariadb and nginx, all on ubuntu.

My nextcloud directories with config and data are still available.
I tried to remove the database and build a new one as described, but it looks like the NC installation does not recognize the new and empty database.

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
GRANT ALL PRIVILEGES on nextcloud.* to 'username'@'localhost';
FLUSH privileges;

Is there a description, how to recreate a new database if the nextcloud directories are still available. Perfectly without loosing all configuration.
Would I need to remove the config.php or can this be reused?

Short answer? No bulletproof solution exists. Recommended solution:

Setup a new NC AIO, install all the apps, create all the users, and start moving the data user folder-by-user folder. Then re-scan and verify all data is present, and ask your users to login with a default password you provides them, change their password and setup MFA again, and then you SHOULD be good again.

Agree with Kerasit. The database is not something that can simply be discarded and replaced. You will basically need to set up a brand new installation and then migrate user data into it.

…that may be true as long as you didn’t use calendar, contacts, bookmarks and other apps that store their content solely in the database.
At least calendars and contacts can be exported with calcardbackup, as long as you can restore the old database from a backup or you still have access to the old database.

Hello,

It’s slightly off topic,

I use Nextcloud via snap installation and there, it is just 2 command job.

  1. In running system → sudo nextcloud.export
  2. In the new system with snap nextcloud clean installation → sudo nextcloud.import path/to/backup/location

Done.

It will bring everything. Apps, settings, user account, user content & off course database

For reference → How to backup your instance · nextcloud-snap/nextcloud-snap Wiki · GitHub

Thanks.

Which will work because of the SNAP engine. However doing that, AFTER the issues occured, only moved the issues aswell.

Conceptually it would be the same if I did a LXC migrate/copy of my running NC while it was already broken, and expecting it to be not broken at the destination.