It's a tool to migrate a structured database to S3 storage.
First, you must get this project with git or download it in zip format.
git clone https://github.com/arawa/migrate-s3-nc.git
If you have not composer, follow this instruction page to install composer .
It's very important to build this project.
cd migrate-s3-nc
composer install
You must stop the web service to ensure that no one or a technical user use Nextcloud.
# nginx
sudo systemctl stop nginx.service
# apache (Debian based)
sudo systemctl stop apache.service
# or this
sudo systemctl stop apache2.service
# apache (CentOS based)
sudo systemctl stop httpd.service
Use the files_scan.sh
script from the project folder to scan the filesystem of Nextcloud :
# script to scan your filesystem of nextcloud
./files_scan.sh /var/www/html/nextcloud <web-user>
<web-user>
is the user of your web server : nginx
for the nginx, www-data
for the apache CentOS based, apache
or apache2
for Debian based .
Go to Nextcloud folder, example : /var/www/html/nextcloud
, to use occ command line and cleanup the database of nextcloud.
# cleanup your database
sudo -u <web-user> php occ files:cleanup
sudo crontab -u <web-user> -e
Enable the maintenance mode of Nextcloud. This mode prevent the technical user or users to access your Nextcloud's instance.
cd /var/www/html/nextcloud
sudo -u <web-user> php occ maintenance:mode --on
This step is very important. Otherwise, your Nextcloud will recreate the storages in the oc_storages
database table.
Run this command line to backup your database :
mysqldump --user <user-database> --password <database-name> > <database-name>-backup.sql
And particularly the oc_storages
databalse table :
mysqldump --user <user-database> --password <database-name> oc_storages > <database-name>-oc_storages-backup.sql
If you have a problem with the migration, you can just rollback this database table and not the entire database.
Now, you can configure your .env
file.
You must copy the .env-sample
to .env
file and define your config in .env
file.
Here is the content of the .env file.
# Nextcloud Informations
NEXTCLOUD_FOLDER_PATH=""
NEXTCLOUD_CONFIG_PATH="/config/config.php"
# MYSQL Informations
MYSQL_DATABASE_SCHEMA=""
MYSQL_DATABASE_USER=""
MYSQL_DATABASE_PASSWORD=""
MYSQL_DATABASE_HOST=""
#########################################
# #
# You should choice between "S3 Swift" #
# and "S3 Anothers Informations" ! #
# #
# Not both ! #
# #
#########################################
# Required
S3_PROVIDER_NAME=""
S3_ENDPOINT=""
S3_REGION=""
S3_KEY=""
S3_SECRET=""
S3_BUCKET_NAME=""
# S3 SWift Informations (Example: OVH, OpenStack)
S3_SWIFT_URL=""
S3_SWIFT_USERNAME=""
S3_SWIFT_PASSWORD=""
S3_SWIFT_ID_PROJECT=""
# S3 Anothers Informations
S3_HOSTNAME=""
S3_PORT=""
Nextcloud informations :
NEXTCLOUD_FOLDER_PATH
: Is the data folder where the files are storedNEXTCLOUD_CONFIG_PATH
: Is the config file of Nextcloud. It's the only file to not modif
MySQL informations :
MYSQL_DATABASE_SCHEMA
: The database nameMYSQL_DATABASE_USER
: The applicative user to connect to databaseMYSQL_DATABASE_PASSWORD
: The password of your applicative userMYSQL_DATABASE_HOST
: The hostname of your database (onlylocal
works)
S3 Informations :
These env vars are required
S3_PROVIDER_NAME
: The provider name. For example :OVH
,SWIFT
,Scaleway
,AWS
,Dell
, and so on.S3_ENDPOINT
: The URL of your object storage serverS3_REGION
: The region of you object storage serverS3_KEY
: The key to use object storage server's APIS3_SECRET
: The secret which is with theS3_KEY
S3_BUCKET_NAME
: The bucket name in your S3 server
These env vars are required if you use SWIFT (ovh
, swift
, openstack
)
S3_SWIFT_URL
:S3_SWIFT_USERNAME
:S3_SWIFT_PASSWORD
:S3_SWIFT_ID_PROJECT
:
If you use a swift S3 (OVH, OpenStack, Swift and so on. ) :
# Nextcloud Informations
NEXTCLOUD_FOLDER_PATH="/var/www/html/my-nextcloud"
NEXTCLOUD_CONFIG_PATH="/config/config.php"
# MYSQL Information
MYSQL_DATABASE_SCHEMA="nextcloud"
MYSQL_DATABASE_USER="nextcloud"
MYSQL_DATABASE_PASSWORD="123456789"
MYSQL_DATABASE_HOST="localhost"
#########################################
# #
# You should choice between "S3 Swift" #
# and "S3 Anothers Informations" ! #
# #
# Not both ! #
# #
#########################################
# Required
S3_PROVIDER_NAME="OVH"
S3_ENDPOINT="https://s3.par.cloud.ovh.net"
S3_KEY="dj9dalxnxxdock1xnij4k5tl0aent22v"
S3_SECRET="gtqkfradr7905d7sl6jxkwm2i0ll5ankg"
S3_BUCKET_NAME="my-bucket"
S3_REGION="par"
# S3 SWift Informations (Example: OVH, OpenStack)
S3_SWIFT_URL="https://auth.cloud.ovh.net/v3"
S3_SWIFT_USERNAME="my-user"
S3_SWIFT_PASSWORD="Nq2jjNpTfQFiLMYUCGW8NcNvtf3nHVe2"
S3_SWIFT_ID_PROJECT="5121915117413912"
# S3 Anothers Informations
S3_HOSTNAME=""
S3_PORT=""
If you use a S3 compatible (Scaleway, Dell, AWS S3, Minio and so on.) :
# Nextcloud Informations
NEXTCLOUD_FOLDER_PATH="/var/www/html/nextcloud"
NEXTCLOUD_CONFIG_PATH="/config/config.php"
# MYSQL Information
MYSQL_DATABASE_SCHEMA="nextcloud"
MYSQL_DATABASE_USER="nextcloud"
MYSQL_DATABASE_PASSWORD="sLK15Aa875/0!sqd"
MYSQL_DATABASE_HOST="localhost"
#########################################
# #
# You should choice between "S3 Swift" #
# and "S3 Anothers Informations" ! #
# #
# Not both ! #
# #
#########################################
# Required
S3_PROVIDER_NAME="Scaleway"
S3_ENDPOINT="https://s3.fr-par.scw.cloud"
S3_KEY="SD130KQ19SL01L0"
S3_SECRET="ca97csd8-0t80-asf1-8c2a-ba69662az3e0"
S3_BUCKET_NAME="my-bucket"
S3_REGION="fr-par"
# S3 SWift Informations (Example: OVH, OpenStack)
S3_SWIFT_URL=""
# S3_ENDPOINT="https://storage.sbg.cloud.ovh.net/v1/AUTH_177b256fb8674b9c9880b575191b9709"
S3_SWIFT_USERNAME=""
S3_SWIFT_PASSWORD=""
S3_SWIFT_ID_PROJECT=""
# S3 Anothers Informations
S3_HOSTNAME="s3.fr-par.scw.cloud"
S3_PORT="443"
After all these, you can go in the How to run ?
part !
First, you must build with composer command-line : composer install
from the project folder.
You must run this command to starting the migration :
$ php main.php
After its execution, it prints this message :
Congrulation ! The migration is done !
You should move the new_config.php file and replace Nextcloud's config.php file with it
Please, check if it's new config is correct !
It means the script has run with success !
You must check the good config in the new_config.php
file before replace it with the Nextcloud's config.php
file.
new_config.php
to config.php
on all the servers in your web cluster if you have one.
Once the copy is done. You can check in your oc_storages
database table if it's correct :
MariaDB [nextcloud]> select * from oc_storages where id like "%home%";
Empty set (0.000 sec)
Then, you must :
- Decomment cron tasks
- Disable Nextcloud's maintenance
- Enable your web server (nginx, apache and so on)
- Dotenv : To set your config.
- Aws SDK Php : To push your files.
You can purge your bucket with the purgeBucket.php file. It's very useful when your migration has been stopped abruptly.
php purgeBucket.php
🚨 Caution : This program deletes all objects in your bucket and you must rollback your database, in particular the oc_storage
database table. Then, begin the migration from How to run ? part.
The initial code of this software has been developed by Arawa with the financial support of Sorbonne Université.