How to downgrade Nextcloud

If you don’t upgrade your server in several months, you might find yourself in a situation where your Nextcloud doesn’t work. The cause of this might be you skipping a major Nextcloud version during update.

For example, before update your Nextcloud is on version 27. After update it is on version 29. This is not allowed by Nextcloud, and it will enter the maintenance mode. Instead, you have to update Nextcloud to version 28 first, and only after that install version 29. How to do it if you are on version 29 already?

If you were on version 25, you would need to do several upgrades: 25 -> 26 -> 27 -> 28 -> 29 in correct order.

Entering your server’s root shell

Steps discussed in this manual require you to use a root shell of your server. Here is the manual on how to get root SSH access:

How do I check if this problem applies to me?

Run the following command to check the status of your Nextcloud updater progress:

systemctl status nextcloud-setup.service

The error message should also tell you what Nextcloud version you should actually use. If your logs are cropped, use this to see all logs (strings will be shown in reverse order)

journalctl -r -u nextcloud-setup.service

Once you figure out what version you should use, you can install it.

Downgrading Nextcloud

We provide several branches of Nextcloud module for you to use. Here they are:

  • flakes is the primary branch that is used by SelfPrivacy. The most recent version is there and you should return to this branch in the end after downgrading. As of writing this post, it is Nextcloud 29.
  • inex/nextcloud28 will install Nextcloud 28.0.10.
  • inex/nextcloud27 will install Nextcloud 27.1.11.
  • inex/nextcloud26 will install Nextcloud 26.0.13.

To change a branch you will need to edit the /etc/nixos/sp-modules/flake.nix file.

This command will open this file in text editor Nano:

nano /etc/nixos/sp-modules/flake.nix

The file should look like this:

{
  description = "SelfPrivacy NixOS PoC modules/extensions/bundles/packages/etc";

  inputs.bitwarden.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/bitwarden;
  inputs.gitea.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/gitea;
  inputs.jitsi-meet.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/jitsi-meet;
  inputs.nextcloud.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/nextcloud;
  inputs.ocserv.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/ocserv;
  inputs.pleroma.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/pleroma;
  inputs.simple-nixos-mailserver.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/simple-nixos-mailserver;

  outputs = _: { };
}

Find a line for Nextcloud there. It starts with inputs.nextcloud.url. There you will see this segment: ?ref=flakes. You will need to replace flakes with a branch you would like to use. If you want to install Nextcloud 27, the line will look like this:

inputs.nextcloud.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=inex/nextcloud27&dir=sp-modules/nextcloud;

Save the file. To do this in Nano, press Ctrl+X, then type y to save, and press Enter to confirm the file name.

After you do this, you will need to actually install the selected Nextcloud version. To do this, you will need to run the following 3 commands.

cd /etc/nixos

Will make sure you are in a correct folder.

nix flake update --override-input selfprivacy-nixos-config git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes

Will fetch all required metadata.

NIXPKGS_ALLOW_INSECURE=1 nixos-rebuild switch --flake .#default --impure

Will install your desired Nextcloud version. We allow insecure packages here because old Nextcloud versions are considered insecure by Nixpkgs team.

After the proccess is finished, check the logs of the Nextcloud setup service.

journalctl -r -u nextcloud-setup.service

The lines of interest for us are:

Update successful

means that you’ve migrated fine.

If you also see this

Maintenance mode is kept active

it means that you might need to exit maintenance mode manually. To do so, run this command:

nextcloud-occ maintenance:mode --off

After all of this, open Nextcloud in your browser. If everything is ok, repeat the proccess for the next version until you reach the flakes branch.

2 Likes