Skip to main content

Migrate Nextcloud To Another Server

Restoring from backup. Use this same method for migrating. 

1) You use Rsync to move the backed up files to the new server. It will keep the tags and other permission that the backup was oriniglally stored with. If you don't care about that, just copy it. (rsync s pretty quick and copying either way).

First things first. 

Put the files in the correct locations (using Rsync) that they need to be in. Where ever the volume locations are going to be, put them there.

Before you start up, everything needs to be where they go.
    IF you are using docker (like me), make sure the volumes are loaded with the old data.

Copy your full set of files. The main data files and the database files using this... It will keep the 

rsync -Aax backup/directory/location new/directory/location

Command explained:

The flags -Aax in the command rsync -Aax backup/directory/location new/directory/locationhave the following meanings:

  • -A (or --acls) preserves the ACL (Access Control Lists) permissions when transferring files.
  • -a (or --archive) is a combination of multiple flags that preserves almost everything (recursive, preserves symlinks, file permissions, modification times, group, owner, etc.) except ACL and extended attributes.
  • -x (or --one-file-system) ensures that rsync does not traverse filesystem boundaries.

Find your config file and edit it so that it is relevant to your new/current server.

/data/config/config.php

If you don't have a config new enough, start a new instance of nextcloud so that it will create one. From there, use that config.php file. 
Delete all the files and start over while keeping the copy of that config file. 

If using a docker-compose yaml file, compare your database and other info on there with the config.php file to make sure everything is correct. 
    The password used in your old database needs to be reflected in here as well. 

If none of that works, try the below but I have not been able to get past step 5 using docker.

Setting up the New Server

  1. Install the Operating System: Set up the new machine with the desired operating system.
  2. Configure Web Server and PHP: Install and configure the web server (e.g., Apache or Nginx) and PHP for Nextcloud. Ensure that the PHP version matches Nextcloud's supported configuration, and all relevant PHP extensions are installed. Also, set the appropriate permissions and file upload size limits.
  3. Set up the Database: Set up the database and ensure it's a Nextcloud-supported configuration.
  4. Copy Configuration (Optional): If your original machine was installed recently, you can safely copy the base configuration from the old server to the new server as a best practice.

Migrating Data from the Old Server

  1. Enable Maintenance Mode: On the old server, stop Nextcloud and activate the maintenance mode. Wait for 6-7 minutes to allow all sync clients to register that the server is in maintenance mode.

    1. Note: if you do not have a running older system or have only files/folders of that system, there is no need to put it into maintenance mode as there is no front end client to pause. 
  2. Stop Nextcloud: After the waiting period, stop the application and/or web server that serves Nextcloud.

  3. Create a Database Backup: Create a dump of the database on the old server and copy it to the new machine. Then, import the dump into the database on the new server. (See "Backup and Restoring backup" for more details.)

  4. Copy Nextcloud Files: Copy all files from your Nextcloud instance on the old server, including the Nextcloud program files, data files, log files, and configuration files, to the new machine. Ensure that the data files retain their original timestamps (you can use rsync with the -t option) to prevent clients from re-downloading all files after the migration. Note that the file locations may vary depending on the original installation method and operating system. On the new system, make sure to place the files in the appropriate locations. If you change any paths, adapt the paths in the config.php file accordingly. (See "Backup and Restoring backup" for more details.)

  5. Check Data Fingerprint: Check the config.php file of the old system to see if it has the data-fingerprint set to a non-empty value. If so, run the maintenance:data-fingerprint command on the new system, similar to how it's required when performing a backup restoration. (See "Restoring backup" for details.)

Testing and Finalizing the Migration

  1. Test the New Server: While Nextcloud is still in maintenance mode on the new server (confirm!), start the database, web server, and application server. Access the migrated Nextcloud instance in your web browser. Confirm that you see the maintenance mode notice, log entries are written by both the web server and Nextcloud, and no error messages occur. Then, take Nextcloud out of maintenance mode and repeat the testing. Log in as an admin and confirm that Nextcloud is functioning normally.

  2. Update DNS: Once you've confirmed that the new server is working correctly, change the CNAME entry in the DNS to point your users to the new server's location.

Full article from Nextcloud:  
https://docs.nextcloud.com/server/stable/admin_manual/maintenance/migrating.html