Do you know how to perform Mailcow migration to new server? This blog will explain how you can move to new server and your data. Here, I will explain the native method, backup & restore script, and a professional way to transfer your Mailcow files.

Why Migrate Mailcow to New Server?

Before going through the methods, let’s know why there is a need to transfer from old Mailcow server to a new one.

  • Your old server is getting slow or laggy, so moving to a new one makes the CPU faster, more storage that improve the email performance.
  • An aging server causes hardware failure, downtime, and increased cost. So, to resolve it, move to new server.
  • For better pricing, features, or support, transfer to a new VPS, dedicated server, or another cloud provider.
  • Over time, your disk space is used to store large mailboxes and attachments. Transferring is needed to reduce the space.
  • If your existing server is creating issues like corruption, unexpected failure, etc., moving to a new one helps you to recover them.
  • You want to increase service availability for users or move to a data center/region. They have to transfer to another server.
  • Some want to move from on-premises Mailcow to a cloud-hosted server for scalability and remote management.

Preparations Before Migrating to New Server

You understand the reasons, but for a smooth migration, you must follow this checklist.

  • Check that your destination server has enough disk space to move all the mailbox data.
  • Lower your TTL for MX, A, and related DNS records to speed up DNS propagation.
  • Make sure you inform all the users about the migration and tell them to avoid sending or receiving emails during the migration.
  • Before you go through the migration, backup your Mailcow data first. To prevent any risk of data loss.
  • Stop Docker on the source server before you start the final synchronization. This is to prevent new emails or mailbox changes during the process.

Manually Migrate Mailcow to New Server with Native Method

Mailcow supports native migration from an existing Mailcow server to a new empty server. In this method, the target server must be empty or brand new. This is because when it moves the server to the destination server, it will delete the existing Docker volumes. If you move to an already used server, your Docker data will be erased. So, when you are moving from server to server, you need an empty destination Mailcow server. This process will be lengthy, so I am going to divide them in severs steps.

Step 1: Prepare Empty Target Server

Start by logging into your Target or new server using SSH, then install the runtime essentials.

  1. Run this command to install the prerequisites: sudo apt update && sudo apt install -y rsync curl git
  2. Install Docker Engine: curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
  3. Stop Docker so that it does not lock files when you have to sync data: sudo systemctl stop docker.socket docker.service
    Replace ://yourdomain.com with your mail server’s FQDN: sudo hostnamectl set-hostname yourdomain.com

Step 2: Setup SSH Trust & Live Background Sync on Source Server

  1. Generate SSH key: ssh-keygen -t ed25519
  2. Copy the key, replace target-server-ip with new server IP address: ssh-copy-id root@target-server-ip
  3. Run these commands while your source Mailcow is online. This transfers all your data.
    rsync -aHhP --numeric-ids --delete /opt/mailcow-dockerized/ root@target-server-ip:/opt/mailcow-dockerized/
    rsync -aHhP --numeric-ids --delete --exclude '*rspamd-vol-1' /var/lib/docker/volumes/ root@target-server-ip:/var/lib/docker/volumes/

Step 3: Stop Source Services & Final Delta Sync

  1. After migrating your data, stop Mailcow to freeze database writes and queue delivery.
    cd /opt/mailcow-dockerized
    docker compose down

    # Stop the Docker engine on the old host
    sudo systemctl stop docker.socket docker.service
  2. Re-run the exact same commands to transfer only minor changes
    rsync -aHhP --numeric-ids --delete /opt/mailcow-dockerized/ root@target-server-ip:/opt/mailcow-dockerized/
    rsync -aHhP --numeric-ids --delete --exclude '*rspamd-vol-1' /var/lib/docker/volumes/ root@target-server-ip:/var/lib/docker/volumes/

Step 4: Start Mailcow on Target Server

Now, log back into the target server to get your container on the newly cloned data.

  1. Enable Docker Daemon and start it: sudo systemctl enable --now docker.service
  2. Get Images and start your Stack: cd /opt/mailcow-dockerized
    docker compose pull
    docker compose up -d
  3. Lastly, update your DNS records and configure rDNS for the new IP to point back to ://yourdomain.com

Use Backup & Restore Script to Transfer Mailcow Files

Mailcow has built-in backup and restore scripts that can also be used to move your files. For this, you must have installed rsync and SSH on both servers. Make sure Mailcow is installed and properly running on the new server. Ensure that both servers use the same Mailcow version.

  1. Start by navigating to the Mailcow installation folder: cd /opt/mailcow-dockerized.
  2. Run this backup script to save old server databases, emails, and configurations: MAILCOW_BACKUP_LOCATION=/var/tmp/mailcow_backup ./helper-scripts/backup_and_restore.sh backup all
  3. Using rsync, move the backup data to the new server: rsync -avz -e ssh /var/tmp/mailcow_backup/ root@NEW_SERVER_IP:/var/tmp/mailcow_backup/
  4. Copy your exact mailcow.conf file so that the settings will match:
    rsync -avz -e ssh /opt/mailcow-dockerized/mailcow.conf root@NEW_SERVER_IP:/opt/mailcow-dockerized/mailcow.conf
  5. Switch off the new server container to overwrite the database: cd /opt/mailcow-dockerized
    docker compose down
  6. Run this restore script and point it towards your transferred files: MAILCOW_BACKUP_LOCATION=/var/tmp/mailcow_backup ./helper-scripts/backup_and_restore.sh restore
  7. The script asks you what to restore. Type All and press the Enter key.
  8. Now, get the container back online on the new server: docker compose up -d
  9. Confirm all the services are running smoothly with this code: docker compose logs --tail=100 -f.

After you properly migrate your Mailcow server to the new one, don’t forget to update your DNS records. Failing to do the migration will cause the server to not receive emails. If your server’s public IP address changes, then update the SNAT_TO_SOURCE value in mailcow.conf. If not, SOGo will not function properly. These methods completely migrate Mailcow to new server. If you want to move only emails. This next method will be suitable for you.

Transfer Mailcow Only Mailbox to New Server

Specialized software like the SysTools IMAP Migration Tool is a great way to migrate your emails. This is a dedicated utility that migrates multiple mailboxes to another email server using IMAP. Mailcow supports IMAP, so it becomes easier to move them directly. It is a secure solution that transfers all mailboxes while preserving the original content, attachments, and metadata.

Instructions for Using Software

  1. Start by installing the software, then click on IMAP on both the source and destination tab.
    choose imap
  2. Click the Email button and apply a date filter for selective migration.
    select emails
  3. Configure your source Mailcow account using the email address and password.
    configure your source account
  4. Then, also, select your destination and provide the important details. Click Validate.
    add destination server
  5. Add source user account by submitting a CSV mapping file. Press Start Migration.
    begin the process
Concluding Words

There are native and backup ways for Mailcow Migration to a new server. These methods require using commands. So before that, follow the preparations and backup your data. Then, properly follow the steps of the methods. If you only want to move the mailbox, the dedicated software will be a great choice.