NC Server and database corrupted - howto recover?


my NC server crashed and now I try to recover all.

All files under www/nextcloud and www/nextcloud_data are available but the database (postgresql) has gone. I tried to import the old data into new postgresql by a psql dump but this failes. psql finishes without any error but there are no database nor data imported.

Is there any way to recover the database by using the nextcloud_data folder in a fresh NC installation?

My idea is to install NC from scratch and then make an update of the “empty” Database using the nextcloud_data folder. Is this doable? And if so, how?



I also newbie, normally I doing backup once a week using nextcloud.export command and compress it to tar.gz, when restoring to new server, I just installed new ubuntu server, setup new nextcloud, and do the nextcloud.export agian, then when restoring, I restore the previous backup from my old server, its working without any problem.

Well, if you’ve lost your database, but still have your data files then you’ll at least have your data files. You can’t certainly deploy those files into a new (clean) Nextcloud installation then run a file scan (see the Admin Manual for specifics).

With the loss of your database you will of course have to create new users, have lost all previous shares, and also lost data associated with various apps (e.g. calendar). None of that is stored in your data files.

If you have a dump of your database (a backup), doing a restore from it is straightforward. What, precisely, was the process you followed? i.e. what commands/etc

I have a backup of the database but recovery fails. The dump runs wihtout any problem, but do not create a database on the new server. I must have made a mistake while creating the dump. Unfortunately I did’t have checked the dump if I can restore it, so it seems that it is useless.

I was doing such a migration right two weeks ago and it worked. But this was before the crash.

Today I tryed the wizard to install NC but this failed also. I always get messages that the DB user I provide must already exist. But, it exists. All is fine, since I can connect from other machines without any problem. But the php installation process is triggered to throw an exception, that the user doesn’t exist.

Same for the command line installation.

quila:/srv/www/nextcloud# sudo -u www-data php occ maintenance:install --database "pgsql" --database-name "nextcloud" --database-user "nextcloud" --database-pass "xxx" --admin-user "admin" --admin-pass "xxx"
PostgreSQL username and/or password not valid
 -> You need to enter details of an existing account.
Trace: #0 /srv/www/nextcloud/lib/private/Setup.php(356): OC\Setup\PostgreSQL->setupDatabase()
#1 /srv/www/nextcloud/core/Command/Maintenance/Install.php(115): OC\Setup->install()
#2 /srv/www/nextcloud/3rdparty/symfony/console/Command/Command.php(298): OC\Core\Command\Maintenance\Install->execute()
#3 /srv/www/nextcloud/3rdparty/symfony/console/Application.php(1040): Symfony\Component\Console\Command\Command->run()
#4 /srv/www/nextcloud/3rdparty/symfony/console/Application.php(301): Symfony\Component\Console\Application->doRunCommand()
#5 /srv/www/nextcloud/3rdparty/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun()
#6 /srv/www/nextcloud/lib/private/Console/Application.php(211): Symfony\Component\Console\Application->run()
#7 /srv/www/nextcloud/console.php(100): OC\Console\Application->run()
#8 /srv/www/nextcloud/occ(11): require_once('...')
#9 {main}

postgres=# \du
                                      Liste der Rollen
 Rollenname |                            Attribute                            | Mitglied von 
 nextcloud  | Superuser, Rolle erzeugen, DB erzeugen                          | {}
 postgres   | Superuser, Rolle erzeugen, DB erzeugen, Replikation, Bypass RLS | {}


Since the user exists, it also could be a wrong password. But it is always copied from my pw container, so I can exclude typos. As sad, with the provided credentials for NC, I can connect from other computer to my server.

I am a little clueless now.

it smells like a bug!

  1. Attempt to restore the postgresql database

It seems to be a bug or a version issue.

The dump was made by PostgerSQL server version 13 and has to be restored on a 15. But I have no idea why this should be an issue.

fact: Trying to restore via pgsql < dump.sql failes. Copying the sql via copy&paste into pqsl works.

  1. Attemp to install a clean NC

I do not know any internals about the installation of NC. The error of missing user or wrong password is strange but could be related to any possible bug in postgresql 15.

Since I prefere restoring the database and not to install a clean NC, I will now switch to a postgresql forum or mailing list.

thanx so far


OK, just a second after I posted my answer the solution poped up on my mind

Just using pgsql -d Nextcloud -f dumpfile.sql worked fine.

No bug, but silly operator. … as quite almost … :frowning:


NC is fully running again! Recovery succesfull! Mission accomplished!

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