March 8, 2021

Problems updating to Nextcloud Hub 21

Guides self-host nextcloud

Paul Kelly

I was having some problems uploading photos from my phone to the instance of Nextcloud I have running on my local server, so after checking all the obvious stuff; server was running, tailscale was working (another post on this to come shortly) I checked for updates on both the Android app and the docker image. This is when things went horribly wrong!

The Android app was upto date, but there was a newer docker image, so I restarted the docker container, it dutifully downloaded, then I was greeted with the following:

Screenshot of an error when upgrading Nextcloud to version 21

I was confused by the error, the system thought I was updating two major versions. That didn’t sound correct, I know I don’t update my containers as often as I should (I will be installing watchtower after this mess!), but I am certain I have updated in the last few months so should at least have been on version 20.

At this point I seriously thought about ditching the current install and moving my data over to a brand-new container running V21. I thought I had put myself in a situation I couldn’t get out of with an upgraded database, but the system not upgraded and no way to downgrade and start again. But I decided to carry on trying to fix it as it would bug me if I didn’t find the underlying cause.

The next thing to check was the config file in the Nextcloud data directory (/config/config.php) and found the version listed there was 19.0.0.8:

'datadirectory' => '/var/www/html/data',
'dbtype' => 'mysql',
'version' => '19.0.0.08',

The config file is meant to be updated automatically as part of a system upgrade, so it has the correct version in it. This obviously wasn’t happening, and while it would not error with V20 upgrades, this is what was giving me the problem when it went to V21 and thought it was two major versions behind.

I updated the config file to the latest version (21.0.0.18) and restarted the container.

This time I was met with the following:

Screenshot of the update screen for upgrading Nextcloud to version 21

This was more promising, however, it errored out while performing the upgrade. I decided to try a manual upgrade to see if either it would work, or at least give me a better error message as to what had gone wrong.

To attempt a manual upgrade within a docker container I needed to get to a command line. The easiest way was via Portainer, which I use to manage my containers.

Going to Console for the container and then setting the user to be www-data (double check who owns the occ file in ~/html by logging in as root and then ls -l in the directory you are dropped into, if it is a user other than www-data then login again as that user).

Screenshot of the portainer user console

I ran the manual upgrade command:

 ./occ upgrade 

And whatdya know? It completed successfully. Well, it left the site in maintenance mode, so I had to switch it off.

./occ maintenance:mode —off

My instance finally came up. There was a bit of config to install some of the apps that had been disabled in the upgrade, but in the end my photos started uploading again and the instance seems to be working fine.

So now I need to check the permissions on the config file and see what happens next time there is an upgrade, and I am also going to get a WatchTower container setup to keep my images up to date.