At the time of writing this script using S3 based primary storage in Nextcloud does not work very well. Still you might have configured your Nextcloud to use S3 based primary storage as indicated here. But what if you want to switch to local primary storage?
Officially it is not supported to change the primary storage in Nextcloud. However, it's very well possible and this unofficial script helps you in doing so. It will transfer files from S3 based primary storage to a local primary storage.
Related topics on the Nextcloud community are:
- https://help.nextcloud.com/t/migrating-from-s3-primary-storage-to-local-storage/77639
- https://help.nextcloud.com/t/change-s3-primary-object-storage-to-local-storage/89420/2
- https://help.nextcloud.com/t/switching-primary-storage/11915/2
Just follow the steps below:
- Run composer install to obtain some dependencies.
- Make sure that the Nextcloud cron job is disabled.
- Make sure that you local data is sufficiently large.
- Setup the three path variables at the top of the transfer.php file.
- Then just run the transfer.php file from the command line. Make sure to run the script as the system user that is normally used for running Nextcloud to avoid permission errors and maybe increase the memory limit to avoid nasty errors (e.g. execute
sudo -u nextclouduser php -d memory_limit=1024M transfer.php
). That's it! 🏁
If everything worked you might want to delete the backup folder and S3 instance manually. Also you probably want to delete this script after running it.
This script was tested successfully on Ubuntu 18.04 using a Maria SQL database and DigitalOcean Spaces as S3 object storage. The Nextcloud version was 17. Please make sure to review the script carefully before you run it to avoid any issues. Consider it as a prototype and not a finished tool.
If you find this script useful and you make some modifications please consider making a pull request so that others can benefit from it. This would be highly appreciated!
This script is open-sourced software licensed under the MIT license. Please see LICENSE for details.