Nextcloud existing database

How do I use a previous database?

did you install Nextcloud yourself? Otherwise I wonder why you see the setup page. Usually DietPi install option is able to pick up existing SQL dumps during installation, if available on specific place.

I always install from the Dietpi list of programs, but this time a different screen appeared, and since I’m a bit of a novice at this, I got lost.

You don’t have log from NC installation? You still have old database dump available?

Did you install Nextcloud freshly or was it a reinstall or does a previously running instance suddently show the setup page?

This looks like the config.php does not exist, or just a template without mandatory content like database info. Can you check:

cat /var/www/nextcloud/config/config.php

Usually it should contain info that mysql database is used, with table prefix, user, and password. But do not paste it here without masking the password(s) and incase instance ID and such.

It looks like this is a classic case of a Nextcloud config mismatch, not a broken install. If it suddenly takes you to the setup screen, 9 times out of 10, config.php is missing, empty, or pointing to a database that doesn’t exist anymore. Because you installed it with DietPi, it usually finds the database automatically during setup. Something probably went wrong during the last change or reboot.

Look at /var/www/nextcloud/config/config.php. As MichaIng said, the most important things to look for are dbtype, dbname, dbuser, and dbpassword. Nextcloud thinks it’s a new install if that file is missing or has been changed back to a template. It’s also a good idea to check that the database service is running and that the old DB is still there.

If you still have the old database dump, recovery is usually easy. But if the config file is missing, Nextcloud won’t automatically reconnect. This happens a lot on DietPi when storage paths or permissions change a little bit.

1 Like

Got the config via PM. It is a minimal one, looks like /var/www/nextcloud/config/config.php was missing entirely, and @negubill entered some database info via web UI setup dialog, but most likely not functional, at least does not match the database table we set up in dietpi-software.

Verify the following:

ls -l /mnt/dietpi_userdata/nextcloud_data # should be present with a bunch of content, including a data subdir per user
mysql -e 'show tables from nextcloud' # should show a long list of tables with "oc_" prefix

If above directory and tables exist, all is good, but we’d need to find the lost config.php. Best would be certainly if you have a backup. Otherwise Nextcloud creates backups on every update:

ls -l /mnt/dietpi_userdata/nextcloud_data/updater-*/backups/nextcloud-*/config/config.php

Take the newest one. When you access the web UI, it will most likely look like you just did an update which you need to perform, since the config.php contains an old version string. But that shouldn’t cause any issues, just some redundant migration steps, no harm to repeat.

well this will happen on every system if permissions don’t fit.

[FAILED] Setting could not be added after desired line                                                               │
│                                                                                                                      │
│ The pattern $4                                                                                                       │
│         ‘dbpassword’                                                                                                 │
│ could not be found in file $3                                                                                        │
│         /var/www/nextcloud/config/config.php                                                                         │
│                                                                                                                      │
│ Please retry with valid parameter $4 or apply the setting manually:                                                  │
│         ‘mysql.utf8mb4’ => true,

A reinstall won’t help without restoring a somewhat normal config.php, and otherwise is a noop anyway.

As said, you need to restore a proper config.php from either a manual backup or from last Nextcloud update as mentioned above.