Moving a Nextcloud installation to another server

Hello everyone,

I am new here, and I can’t seem to find a thread concerning the issue I am facing, even though I can hardly imagine I am the first one to attempt this. Please excuse me if I bother you with something that could have been solved with better search skills …

I am running Nextcloud on a server, I use the Webdav, Caldav and Carddav capabilities.
I want to move the nextcloud installation – along with the domain name – to another server of another webhoster.

I am not sure how to start the process and in what order.
I suppose I will need the files from the FTP server as well as the MySQL database. Is there anything else?
I am looking for a way to switch servers with the least amount of downtime possible. Is there a way to already have everything up and running when I transfer the domain to the new hoster?

Any advice is greatly apprerciated!
Many thanks in advance
Per
Hamburg, Germany

3 Likes

https://www.c-rieger.de/clone-your-nextcloud/
https://www.c-rieger.de/nextcloud-backup-and-restore/

I’m using restic for backup and restore.
https://restic.readthedocs.io/en/latest/010_introduction.html
you can create a restic repository on your new server using SFTP as protocol.
if you can read jinja templates you will find a backup script here:

Oh, thanks! I am looking into this.

Unfortunately, I am not as advanced a user by far.
I shouldn’t use anything starting with “sudo”, because I wouldn’t even know where to enter it to begin with. :frowning:

Actually, I was hoping for a solution that would not involve anything beyond my webhoster’s customer control panel (for the database) and an FTP program – that’s about what I can handle, IT-wise …

1 Like

ok. you are using a web hoster.
I’m not sure but the following should work.

  • Install nc on the new server.
  • Set the old and new server to maintenance mode.
  • Dump the database on the old.
  • Copy the complete data directory to the new server.
  • Restore the database on the new server.
  • Edit the config.php on the new server. I think you have to copy passwordsalt and secret from the old to the new server.
  • Change the DNS record to point at your new server.
  • Turn off maintenance mode on the new server.

If you want to test in between you may access the new server with it’s ip address. If you use ssl you may run into trouble with the certificate and some browser. But that’s another story.

2 Likes

Wow, thank you for the prompt advice! That sounds like something I should be able to do. :slight_smile: I will try, and post my progress.

Thanks again for your support.
I now have installed Nextcloud on both servers, and copied the data folder.
The hoster interface gives me a .dump file of the database.
For the new database, I have access via PHPMyAdmin. Can I import the .dump file there?

If the content of the file looks like this: yes

-- MySQL dump 10.15  Distrib 10.0.34-MariaDB, for debian-linux-gnu (x86_64)
--
-- Host: localhost    Database: nextcloud
-- ------------------------------------------------------
-- Server version       10.0.34-MariaDB-0ubuntu0.16.04.1

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `oc_accounts`
--

DROP TABLE IF EXISTS `oc_accounts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `oc_accounts` (
  `uid` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT '',
  `data` longtext COLLATE utf8_bin NOT NULL,
  PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `oc_accounts`
--

Somewhat like it, yes. But there is no “DROP TABLE” command. Does that mean importing the database contents might create a conflict if the same table are to be created again? Or does it mean nothing will happen?

-- MySQL dump 10.13  Distrib 5.6.21, for Linux (i686)
--
-- Host: 127.0.0.3    Database: db493359
-- ------------------------------------------------------
-- Server version	5.6.19-67.0-log
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `oc_accounts`
--

/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `oc_accounts` (
  `uid` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT '',
  `data` longtext COLLATE utf8_bin NOT NULL,
  PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `oc_accounts`
--

LOCK TABLES `oc_accounts` WRITE;

if you install an “empty” nextcloud you will have an “empty” database. but the tables exist. there will be already some data. like the admin account. but they have to be deleted.

either you dump your old database again with the option “include drop table” checked or you delete all tables in your NEW database before the import. (with phpmyadmin)

Ah, that helps. Thank you. I noticed that checkbox, but I was not sure what it would do …

(I am really grateful that you take the time to explain even these basic things to me.)

It took me a while until I could finally get to it and complete the task.
It all worked like a charm. Thank you very much for your kind support, Reiner! It has been a lot of help.

you’re welcome.

@Reiner_Nippes

i just have a similar but not the same question. like: would it be possible to move a self-hosted nc-instance to a dockerized (new) instance as well?

think so. the steps in my list are quite generic.

you can always exercise in virtual machines (with some test data).

1 Like

thanks… will do!

@Reiner_Nippes Sorry to resurrect this post but I am considering doing this now in the future and everything seems to check out, except that I use SSL FreeEncrypt certs in my current installation.

Do you know how to configure this in the new destination by chance?

Thanks so much!

this depends on your new setup.

somewhere in the web server config is a path to the ssl certs. that must be a valid one. no matter where you got from. (valid one in terms of readable by the web server. the web server doesn’t care if it fit’s to your url or is expired.)

so which how to you want to follow to install nextcloud?

Thanks for the reply!

Well I am using LetsEncrypt with Apache.

What I am trying to do is essentially move the server from CENTos 7 to a clean CENTos8 installation.

Does this jive you think?

sure.
you just have to setup a lamp stack on centos8.
after that you can install and transfer nextcloud.
when you transfer nextcloud you have to make sure that the four “components” fit together. that is: datafolder, config.php, nextcloud (the php code), database dump.