Nextcloud fails to update

The first error is in setup/nextclound.sh, where
echo "ALTER TABLE oc_flow_operations ADD COLUMN entity VARCHAR;" | sqlite3 $STORAGE_ROOT/owncloud/owncloud.db
fails with
Error: near line 1: duplicate column name: entity

OK, maybe I ran the setup twice, and you can only add a column so many times (*). So I commented out that line, and here’s what happened next:

`Upgrading to Nextcloud version 18.0.10

An unhandled exception has been thrown:
Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [14] unable to open database file in /usr/local/lib/owncloud/lib/private/DB/Connection.php:68
Stack trace:
#0 /usr/local/lib/owncloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(1040): OC\DB\Connection->connect()
[stack entries #1 through #47 omitted]`

The database file referenced in setup/nextcloud.sh does exist, and sqlite3 /home/user-data/owncloud/owncloud.db opens the database just fine (and btw, the .schema command shows that the ALTER TABLE worked and the new column is indeed in place). I’m not sure what db it’s trying to open that isn’t. Any suggestions on how to get past this?

Commenting out the source nextcloud.sh line from setup/start.sh allowed me to finish running the setup, reboot, and try again. I also did an apt-get upgrade before all this.


(*) Maybe it’s worth adding a clause that if
sqlite3 $STORAGE_ROOT/owncloud/owncloud.db ".schema" | grep 'oc_flow_operations.*entity'
returns 0, skip the ALTER TABLE step?

You are upgrading Nextcloud to be a different version than MiaB installs (20.0.8)?

I didn’t change that line (or anything else besides the duplicated alter table). I believe the script updates incrementally, from 17 to 18 to 19 to 20. If I’m at 17, do you think I could skip the incremental steps and jump to 20?

What is the current problem you are trying to solve?

Thanks for your help with this.

My current problem is that the upgrade failed and I can’t access my calendar or contacts. When I go to the nextcloud calendar page, I get The server encountered an internal error and was unable to complete your request.

This is surely due to the failed install—it worked before I started. The error message during the install is:

Upgrading to Nextcloud version 18.0.10

An unhandled exception has been thrown:
Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [14] unable to open database file in /usr/local/lib/owncloud/lib/private/DB/Connection.php:68
Stack trace:
#0 /usr/local/lib/owncloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(1040): OC\DB\Connection->connect()

I’m confident that the error is from line 85 of setup/nextcloud.sh,

sudo -u www-data php /usr/local/lib/owncloud/occ upgrade

when called from line 196:

InstallNextcloud 18.0.10 39c0021a8b8477c3f1733fddefacfa5ebf921c68 3.4.1 aee680a75e95f26d9285efd3c1e25cf7f3bfd27e 2.0.3 9d9717b29337613b72c74e9914c69b74b346c466 1.0.0 3bf2609061d7214e7f0f69dd8883e55c4ec8f50a

I’m trying to understand why I’m getting that error message, and failing that, if there’s another way to recover my nextcloud setup.

What version of MiaB are you upgrading from and what version of MiaB are you upgrading to?

I did complete the update of everything but nextcloud, using the setup script I downloaded today. So the version I’m upgrading to is whatever we’re up to right now.

Given that the update completed, how can I find the previous version I’d been using? I’m not seeing it in the logs or admin panel. It’s been several months since the last update, though.

I looks like the first MiaB version to include Nextcloud 20 was version .51 in October 2020. What is the version number you have right now? What command did you use to install it?

It’s entirely possible that it’s been over a year since I upgraded… It was early in the pandemic.
I don’t recall ever doing nextcloud setup using anything other than the mailinabox setup tool. As you can see from this thread, I wouldn’t know how.

Here’s what’s in /usr/local/lib/owncloud/version.php right now:

<?php
$OC_Version = array(18,0,10,2);
$OC_VersionString = '18.0.10';
$OC_Edition = '';
$OC_Channel = 'stable';
$OC_VersionCanBeUpgradedFrom = array (
  'nextcloud' =>
  array (
    '17.0' => true,
    '18.0' => true,
  ),
  'owncloud' =>
  array (
  ),
);
$OC_Build = '2020-10-08T07:23:34+00:00 e61ac0275c791d178c720df320e4a4750172d761';
$vendor = 'nextcloud';

Had you made any changes to MiaB or Nextcloud configurations?

The only changes I make to the mailinabox setup are to the nginx config at /etc/nginx/conf.d/local.conf to host some unrelated web sites.

I may have added some plugins to Nextcloud via its web-based admin page, but I know I’m not qualified to do any direct editing of the config files.

I don’t have experience with modifying Nextcloud. I believe for you to do that you had to unlock admin access, or something of that nature, and I am unable to tell you whether that does or does not impact your current upgrade problem using the normal MiaB upgrade process.

OK, thanks for chatting about this. If I have time in the next few days, I’ll try to see if I can research that unable to open database error. I’ve restored /home/user-data from pre-upgrade backups, so it must be there somewhere…

I’ll also contact the nextcloud group directly.

PS: up at the top of this thread, I noted that you can’t run the mailiabox nextcloud setup twice. I put a note about that and my suggested fix at Nextcloud install can't be run twice · Issue #2076 · mail-in-a-box/mailinabox · GitHub .

If you dare, you might want to try to follow the nextcloud install script manually. As you already mentioned, the error probably occurs with the line sudo -u www-data php /usr/local/lib/owncloud/occ upgrade . To have it log verbosely sudo -u www-data php /usr/local/lib/owncloud/occ upgrade -v
Also, check the access rights of the database. Is it owned by the www-data user?
Finally, Nextcloud upgrade doc notes the command sudo -u www-data php occ maintenance:repair. But I’m not sure exactly what it does, and have never used it myself.

Even the occ upgrade gave me errors about not being able to open the db. In the end, I did just cut/paste from the install script to do a reinstall. The fresh install worked just fine.
Thanks, @openletter and @KiekerJan, for your suggestions.

Maybe it’s moot now, but I’m still a little confounded about how the install script as sudo’d root could modify the db via the alter table discussed above, but owncloud’s occ couldn’t connect to it even to answer basic read-only questions. I never did check the ownership of /home/user-data/owncloud/owncloud.db; a good suggestion that I didn’t think of before overwriting everything. Or, maybe there’s another db being referenced by occ?

1 Like