Severe problems doing a restore

Hi folks,

I’m running a small, private nextcloud installation for personal purposes on a Banana Pi, under Armbian (which is 99,99% Debian compatible), nginx, php-fpm and mariadb.
A few days ago I corrupted the BaPi (running nextcloud 11.0.2 at this time), my bad. But no problem (I thought), as I do a daily backup, as described at https://docs.nextcloud.com/server/10/admin_manual/maintenance/backup.html

I rebuilt the BaPi, but when restoring the database (as described at https://docs.nextcloud.com/server/10/admin_manual/maintenance/restore.html) I got a corrupted nextcloud installation, I got only a white, blank screen when trying to login. After several complete nextcloud install tries (completely deleting nextcloud, purging mariadb and it’s remaining files) I noticed an error in nginx’s errorlog:

2017/03/06 16:43:51 [error] 682#0: *273 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught exception 'Doctrine\DBAL\DBALException' with message 'Failed to connect to the database: An exception occured in driver: SQLSTATE[28000] [1045] Access denied for user 'oc_root'@'localhost' (using password: YES)' in /srv/www/html/nextcloud/lib/private/DB/Connection.php:60
Stack trace:
#0 /srv/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\DB\Connection->connect()
#1 /srv/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /srv/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /srv/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(621): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /srv/www/html/nextcloud/lib/private/DB/Connection.php(147): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /srv/www/html/nextcloud/3rdparty/doctr...

Using adminer to look into the database I saw that the oc_root account mentioned above existed, I tried again and again to install with small variations, no luck, but very timeconsuming.

At last I decided to use an older version of nextcloud, namely 10.0.4, which luckily is still available for download. This worked at the first try. Now I have a working 10.0.4 install, and hesitate to update to 11.0.2. My origin installation of 11.0.2 was based on doing updates. Originally it has been an owncloud installation, migrated to nextcloud 9.something, updated to 10.0.4 and then updated to 11.0.2. This has worked, but doing a fresh install of 11.0.2 and doing a restore has not worked.

And there is a topic I have missed in the admin manual, concrete in the “restore nextcloud” page mentioned above. I’m using the calender and the contacts apps of nextcloud. Doing a restore does not restore this apps, only the data stored in these apps. I had to manually add these apps before doing the restore. Adding the apps after the restore led to an errormessage when trying to add them (havn’t noticed it) I think this needs some clarification in the manual.

Just for the records. Or did I make mistakes ?

edit: sorry for the bad formatting of the errorlog

Do you just backup the disk-image or do you make a database-dump (mysqldump)? If you are doing live-backups of the running database, that can corrupt the database.

I would first try to connect to the database (directly on terminal or via phpmyadmin). Sometimes you can still connect and repair things that are broken.

Thanks for your reply.

I’m doing the backups exactly as described in the admin manual. There is not one word written that the db should be stopped before the db-backup and restarted afterwards :-(. I’m shocked.

As my install is private the activities in the install are manageable, but doing the backup like described in the admin manual opens a way for severe corruptions of the backup, that’s the opposite of best practice :frowning: !

Info in the admin manual should be reliable, dependable, safe. I’m aware of the topic that db’s should be stopped before doing a backup, but I’m not a db specialist, so I thought that if there is not one word in the admin manual mentioning this topic it would be safe to do backups as written in the manual. Very annoying, this should be fixed !

The mysqldump command is ok. The problem I was referring is when you take a snapshot of a virtual machine or directly save the folders of the database (/var/lib/mysql/…).

You should precise exactly what is broken in your restore. Were you able to restore the database and read the content (independently from the nextcloud webinterface)? Perhaps it’s only the database connection which does not work (for whatever reason).

OK, my install is running on real hardware (so I’m not doing snapshots), and I don’t save the directories of the db, but use the procedure from the admin manual with mysqldump

My problem was, that after a restore of the db-dump the nextcloud application was unable to connect to the database, see the nginx error log in my initial post.
This happened reproducibly with nextcloud 11.0.2. Going back to nextcloud 10.0.4 the restore of exactly the same db-dump worked, did not break the connection to the db. I also was not able to connect to the db by using the account that was generated during nextcloud setup by using the mysql command. But I was always able to use the mariadb root account which is setup during the installation of mariadb with apt-get.

With 10.0.4 I had a second problem, that a db-restore restored the data of the calender and contact app I used, but not the apps itself. I had to activate them manually before doing the restore.

Meanwhile I have a 100% running 10.0.4 install (as far as I have tested), but I hesitate to update nextcloud to 11.0.2, I fear I get the same situation as described above.

Have no fear! your issue stems from ‘Access denied for user ‘oc_root’@‘localhost’’!

A few things to note when restoring next cloud to new system. When nextcloud installs it generates a new config.php in /var/www/nextcloud/config/

  'dbuser' => 'username',
  'dbpassword' => 'password',

When you import an old database into a new install you have to configure the old database user/password to the new one found in config.php or vice versa.

Therefore I always backup config.php and the database. Do note in your backups which version of nextcloud it contains.

Last but not least it would be wise to create an image of your SD card or install medium as a base to restore from with all your configurations. Then restore the latest database and config.php backup.