[How-to] Migrate ownCloud 10.5.0 to Nextcloud

I am using ownCloud for a pretty long time now but in the last years, things changed. Nexcloud becomes a lot more interesting for users and developers. Therefore, I decided to switch from the latest ownCloud version to Nextcloud. First I thought this would be an easy thing because the foundation of both systems is mainly the same. It turned out that an upgrade from ownCloud version 8.2 - 10.0 is pretty easy with the official migration guide but it becomes a lot harder with newer releases because both systems drifted apart. Thus, switching from ownCloud 10.5 isn't that easy and (officially) not supported. I decided to give it a try and successfully made a migration without data loss and with the takeover of the shared folders and federations (so don't worry, you don't need to give your users new shared links).

In this guide, I present to you how to make the migration to Nextcloud and how to fix upcoming bugs.

With the help of some forum posts, user input and bug reports I created this guide and successfully tested it with two installations. The trick is to migrate ownCloud version 10.5.0 with the official migration tool to Nexcloud version 12.0.12 (some bug fixing must be done during the steps). Then, Nextcloud 12.0.12 can be upgraded step by step until the last major release is reached.

Step-by-Step Migration Guide

Let's say your current ownCloud installation is available under https://owncloud.your-domain.com/ and is located on the server in the ownCloud folder.

Side note: It doesn't matter if you have got command line access or simply installed your cloud on a shared web hosting package. This guide should work in both situations.

1. Go into your owncloud folder and download the migration script with

wget https://download.nextcloud.com/server/installer/migrator/index.php

2. Move the migration script into the updater folder with

mv index.php.1 updater/index.php

If you haven't got command line access simply download the script and upload it in the ownCloud/updater folder manually.

3. Visit the script in a browser by accessing https://owncloud.your-domain.com/updater/index.php.

4. A "Migrate to Nextcloud" page should appear. Click the "Start update" button.

5. (Opt.) If you get an error message "The following extra files have been found" in the "Check for expected files" tab, delete the listed files from the owncloud folder and try it again by hitting the "Retry update" button.

6. (Opt.) If you get a "Download failed - HTTP status code: 429 - URL: https://download.nextcloud.com/server/releases/nextcloud-12.0.12.zip" error in the "Verifying integrity", edit the previously downloaded index.php file in the updater folder and comment out the downloadUpdate() call in line 1133:

//$updater->downloadUpdate();

Due to some problems, you have to download the nextcloud-12.0.12.zip file manually and put it in the owncloud/data/updater-[ID]/downloads folder. If it still exists, replace it with the downloaded file. Then, try the migration process once again by clicking the "Retry update" button.

7. (Opt.) If you get a "Signature of update is not valid" error in the "Verifying integrity" check, your nextcloud-12.0.12.zip file is corrupt. Just check step 6 of this instruction.

8. At the end, you can select if you want to keep the maintenance mode active or not. While this tutorial doesn't require command-line access, select "No (for usage of the web based updater)".

9. At the end of the migration process, click the "Go to your Nextcloud instance to finish the migration".

Migrate to Nextcloud

10. (Opt.) Perhaps the error message "This version of Nextcloud is not compatible with > PHP 7.2. You are currently running 7.X." is displayed. This is because Nextcloud 12.0.2 isn't compatible with PHP versions newer than 7.2. Therefore, I recommend changing your PHP version to 7.1 (don't worry, we will edit this back to a newer release later).

11. Now hit the big button shown to start the update process.

12. (Opt.) If you get the error message "Exception: Updates between multiple major versions and downgrades are unsupported." edit the owncloud/lib/private/Updater.php file by commenting out line 234:

//throw new \Exception('Updates between multiple major versions and downgrades are unsupported.');

This will suppress the error message. Reload and try again.

13. (Opt.) If you see the following error message, some database changes must be made to go on.

Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException: An exception occurred while executing 'DROP TABLE oc_accounts': SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails

You now need to go into your database and delete some persistent locks. I think most of the people are using phpMyAdmin. Go into your database management tool of your choice (or simply use the command line), login to the ownCloud database and execute the SQL statement SHOW CREATE TABLE oc_persistent_locks. Remember that the oc_ is the prefix of the database table. Perhaps you have to change this to your custom prefix. The result of the SQL statement should give you a long statement starting with CREATE TABLE [...]. Have a look at the last lines that look similar to these ones:

CONSTRAINT `FK_XXXXXXXXXXXXXXX1` FOREIGN KEY (`file_id`) REFERENCES `oc_filecache` (`fileid`) ON DELETE CASCADE,
CONSTRAINT `FK_XXXXXXXXXXXXXXX2` FOREIGN KEY (`owner_account_id`) REFERENCES `oc_accounts` (`id`) ON DELETE CASCADE

We now have to delete both persistent locks by executing the following SQL statements one after the other. Remember to replace the oc_ prefix with your personal prefix as before and change the FK_XXXXXXXXXXXXXXX1 and FK_XXXXXXXXXXXXXXX2 with your personal ones from the last SQL result.

ALTER TABLE oc_persistent_locks
	DROP foreign key FK_XXXXXXXXXXXXXXX1,
	DROP file_id;
ALTER TABLE oc_persistent_locks
	DROP foreign key FK_XXXXXXXXXXXXXXX2,
	DROP owner_account_id;

Then go back to your cloud website, reload the page and try it again.

14. Done! You successfully migrated your ownCloud to Nextcloud!

15. Rollback step 12 by removing the comment.

16. Upgrade your Nextcloud to the next major versions (upgrade from 12.0.12 to 13.0.12 and so on until you reach the latest version)

17. Upgrade your PHP version (rollback step 10).

References