Migrate NextCloud AIO data directory
When I faced the issue of migrating the storage directory for my AIO NextCloud the official README sent me to a github discussion whit a somewhat vague answer on how to perform the migration. I thought i would document the process for future reference and if this helps someone else perform a migration like this, that’s a nice bonus.
Pre migration tasks
Before performing any big changes like this you should backup everything. I did this in two ways.
- I started by using the AIO interface to create a backup of NextCloud. Remember to save the backup password.
- Then i created a snapshot of my NextCloud host so that i could perform a rollback on the entire host if needed. The NextCloud storage was not on this machine therefore it was not included in the snapshot.
Migration
- Log in to the AIO interface and stop all containers.
- Stop the AIO master-container
sudo docker stop nextcloud-aio-mastercontainer
- Take a snapshot of your host or perform a backup in some other way. This might include copying the docker volume directory (
/var/lib/docker/volumes/
) to another host. - Copy your files while preserving the permissions
sudo rsync -aP /path/to/NextCloudData /path/to/new/directory/
This will create the directory NextCloudData underdirectory
.- -a: Tells rsync to perform an archive copy. This preserves the important meta information like owner and permissions.
- -P: Tells rsync to print progress.
- Remove the master container
sudo docker rm nextcloud-aio-mastercontainer
- Recreate the master container using your initial method but with the new directory set as the
NEXTCLOUD_DATADIR=/path/to/new/directory/NextCloudData
. I used my ansible role docker-nextcloud-aio. - Log in to AIO container and start all containers.
- Log in to your NextCloud and make sure everything works.
Post Migration
The data is now migrated to the new location and the master-container holds the information of where to find the data. You might want to perform the same migration on your backup directory, though you should not save your user-data and backups in the same place.
Conclusion
This migration was a lot easier than the documentation made it seem. I would be happy to see some official instructions in the documentation but i guess this is not something they want you to do since you could ruin your NextCloud setup.