Migrating to a New Server on Docker Nextcloud
- Migrating your Docker Nextcloud to a new server, from backup and restoring.
Table of Contents
Migrating to a New Server
For official documentation you can see official nextcloud pages for migrating to new server .1 Here, I’m going to show how to migrate under docker environment. Assuming you have set up your new system, and nextcloud using docker is installed. Initially, you have to back up your folder on your old system, it consists of 4 things:
- Config Folder
- Data Folder
- Theme Folder
- Database Folder
Depending on your setup, whether you put your volume using default volume mounts, or bind mounts. If you put default configuration under docker documentation, using volume mounts the nextcloud app created volumes called nc_nextcloud
it consisted of config, data and theme folder. The database folder is under nc_db
folder, consist of database folder. Both of them are under /var/lib/docker/volumes/
folder. If you configured it using bind mounts, under different directory, for example /path/to/your/dir
you can backup accordingly.
Backup
Backup documentation also available under official nextcloud page for backup 2
1. Put your old system into maintenance mode
There are two methods of putting your nextcloud into maintenance mode, using php occ or edit directly your config.php file.
docker exec --user www-data nextcloud php occ maintenance:mode --on
or you can edit your config.php
under your data directory or under default nextcloud data
sudo nano /var/lib/docker/volumes/nc_nextcloud/_data/config/config.php
add this on your config.php
"maintenance" => true,
2. Backup your folder
All of my 4 folders are under two volumes, nc_nextcloud
and nc_db
folder. Backup using rsync
to your any backup directory folder to make it easier to navigate. I’m using sudo then the owner of the original folder is not changing based on the user, in this case www-data
.
- Backup config, data, and theme folder
sudo rsync -Aavx /var/lib/docker/volumes/nc_nextcloud/_data/ /your/backup/folder/nc_`date +"%Y%m%d"`
- Backup database folder
sudo rsync -Aavx /var/lib/docker/volumes/nc_db/_data/ /your/backup/folder/db_`date +"%Y%m%d"`
3. Backup your database
Here I’m using MySQL/MariaDB, you can backup according to your database choice
docker exec nextcloud sh -c 'mysqldump --single-transaction -h localhost -u (username) -(db-password) (db_name)' > /path/your/backup-folder/db_`date +"%Y%m%d"`.bak
nextcloud
is container name, username and db_name are supposed to be nextcloud
as well. Put your db-password after dash (-) without a space.
4. Copy your backup folder to your new system
I’m using rsync
and ssh
to my new server. -p 2222
is just the example if you are using port 2222.
sudo rsync -avz -e "ssh -p 2222" /your/backup/folder/ user@remote:/path/to/your/destination
We have finished what we have to do on our old server. Next we’re moving to our new server.
Restore
Assuming you have copied your backup folder to your new server, installed docker, and nextcloud on your new server, now we can proceed. You can see nextcloud official docs for restoring backup .3 The example here is using volume mounts, that created 2 volumes consist of 4 main folders;
nc_nextcloud
, consist of 3 folders;
nc_nextcloud/
+--_data/
+--config/
+--data/
+--theme/
nc_db
, consist of database;
nc_db/
+--_data/
+--...
1. Restore folder
- Restore according to your setup, restore
nc_nextcloud
volumes folder
sudo rsync -Aax /your/backup/folder/nc_`date +"%Y%m%d"` /var/lib/docker/volumes/nc_nextcloud/_data/
- Restore database folder
sudo rsync -Aax /your/backup/folder/db_`date +"%Y%m%d"` /var/lib/docker/volumes/nc_db/_data/
2. Restore database
docker exec nextcloud sh -c 'mysql -h localhost -u (username) -(db-password) (db-name)' < /your/backup/folder_$xxx.bak
nextcloud
is container name, -h argument is your host, localhost is the default, username and db_name are supposed to be nextcloud
as well. Put your db-password after dash (-) without a space.
3. Synchronising with clients after data recovery
Check the config.php
file of the OLD server to see if it has the data-fingerprint set to a non-empty value. If this is the case, make sure to also run the maintenance:data-fingerprint
command on the NEW server, by doing
docker exec --user www-data nextcloud php occ maintenance:data-fingerprint
4. Make sure to see the maintenance mode notice
While still having Nextcloud in maintenance mode (confirm!) and BEFORE changing the CNAME record in the DNS start up the database, Web server / application server on the new machine and point your web browser to the migrated Nextcloud instance. Confirm that you see the maintenance mode notice, that a logfile entry is written by both the Web server and Nextcloud and that no error messages occur. Then take Nextcloud out of maintenance mode and repeat. Log in as admin and confirm normal function of Nextcloud. See the official docs for migrating . After all set, you can change your CNAME or point your domain to your new server.
Nextcloud Official docs, Migrating to New Server . ↩︎
Nextcloud Official docs, Restoring Backup . ↩︎
Last update : Posted by : Ion Orion Sugiarmawan Tags : Notes, Security, Web, Self-Hosting