docker icon indicating copy to clipboard operation
docker copied to clipboard

Migrate from SNAP install to DOCKER install

Open geoff-scott opened this issue 3 years ago • 3 comments

Hello everyone,

I am a new Nextcloud user...I have run into a problem that unfortunately there doesn't seem to be any documentation on the internet to fix.

I installed my Nextcloud installation using SNAP, as was the first thing that came up on the internet search, now I have grown up a little (Linux speaking) and I have realized that DOCKER should have been the way to go from the get-go.

What I would like to do is migrate my SNAP install into a new DOCKER install.

Here is the deal, there is data on my current SNAP Nextcloud install is important and that will take literally hours to re-enter into the new docker system manually. Although it can be done...I rather just migrate all the users and the data associated with a few commands.

If someone were to come up with a good way of doing this migration, there would most likely be a bounty in it for you.

geoff-scott avatar Mar 03 '21 20:03 geoff-scott

UPDATED: 09-09-2022

Hi there I recently did the same and the following resources will help:

  • nextcloud admin handbook https://docs.nextcloud.com/server/latest/admin_manual/maintenance/migrating.html
  • the forum https://help.nextcloud.com/t/how-to-migrate-from-existing-ubuntu-16-04-installation-to-docker/46664/2
  • The nextcloud snap wiki https://github.com/nextcloud/nextcloud-snap/wiki/Migrating-from-nextcloud-snap-to-Nextcloud-server https://github.com/nextcloud/nextcloud-snap/wiki/How-to-backup-your-instance Be sure to read a bit in those especially the last one to backup your instance to have something to revert to (just in case)

There generally are three things to consider:

  • the database The snap uses mariadb so I’d strongly recommend doing the same for docker
  • the data directory Where is your data? Did you leave it in the snap directory or did you enable a custom one? I’ll assume the standard one from now on.
  • The config.php If you still use the standard config don’t bother or just make the settings on the new one

First you should set up a working docker instance (only the containers not users or data) I like docker-compose and would recommend the example config here. Also make sure to have a working backup. You newer know when you'll need it.

the next step is to export your db: nextcloud.mysqldump > my-old-nextcloud.sql And then import it again with docker exec -i nextcloud-db-1 mysql -unextcloud -p<password> nextcloud < my-old-nextcloud.sql (Use the password and user etc you’ve set in the db.env). The container name might vary but if you use docker compose it'll be <folder-name>-<service-name>-1 so if your compose file is in a folder named nextcloud it'll be nextcloud-db-1.

the next step is to copy your data: By default the snap stores your data in /var/snap/nextcloud/common/nextcloud/data/ By default the docker stores your data in a volume called nextcloud in a sub-directory called _data Also docker stores volumes in /var/lib/docker/ So the final command could be something like rsync -avz --delete /var/snap/nextcloud/common/nextcloud/data/ /var/lib/docker/volumes/nextcloud/_data/data

WARNING: This will permanently move your data thus deleting it in the first directory

lastly I’d recommend to use the new default config.php and remake your configs or try to port them over but you could also just copy the config.php file. It'll lay one directory under the data one (/var/snap/nextcloud/common/nextcloud/config/config.php)

How to use an external storage location in docker: Use your favorite search engine for that. In general make a new bind mount or volume into the docker container (under an arbitrary location like /mnt [this is inside the container not the host]). Then change the config.php to search for the data in that folder. Similar to the external data in the snap.


Commands you might find helpful:

  • docker ps list all running containers (helpful to find the nextcloud-db-1 name)
  • docker volume ls list all volumes managed by docker
  • docker volume inspect <id/name> inspect a volume. Also shows where it is stored.

Why migrate away from SNAP? Now after using the docker way for a few years I don't see any reason to migrate away from the snap. If you only deploy this for your family (so around 5 people) there won't be a much noticeable performance gain and you'll lose the easy rollback, auto updates... I was very happy with the setup and did not move away for any snap related reasons. If you aren't familiar with docker just stay with the snap, learn docker with other services and then come back to the migration in a year or so.

Have fun and good luck

Leptopoda avatar Mar 05 '21 21:03 Leptopoda

Wow, that is an amazingly detailed of a response.

Thank you, I will look into all that you have said. You have given me hope whereas before, I had none.

Thank you again,

G

geoff-scott avatar Mar 05 '21 21:03 geoff-scott

Thank you! Will be trying this over the weekend.

bbluez avatar Jul 30 '22 02:07 bbluez