Console Login

Zero-Downtime Database Migration: The Battle-Tested Strategy for Norwegian Ops

The Myth of the "Quick" Dump and Restore

Let’s be honest. If you are still relying on mysqldump for databases larger than 5GB, you are playing Russian Roulette with your uptime. I have seen too many "scheduled maintenance windows" bleed into Monday morning because the restore process choked on disk I/O or the network pipe between Frankfurt and Oslo wasn't as stable as the brochure promised.

In the Norwegian hosting market, where data sovereignty is not just a buzzword but a mandate from Datatilsynet (especially post-GDPR implementation in May this year), moving data isn't just about moving bytes. It's about compliance and latency. If you are migrating a production workload—whether it's Magento, a custom Laravel ERP, or a high-traffic media site—you need a strategy that decouples data transfer from downtime.

This is not a theoretical whitepaper. This is the exact workflow I use to migrate terabytes of data with less than 60 seconds of actual cutover time. The secret isn't magic; it's physics, bandwidth, and the raw I/O power of NVMe.

Phase 1: The Architecture of Sovereignty

Before we touch the terminal, we need to address the infrastructure. In 2018, putting your database on standard SATA SSDs is negligence. The bottleneck during a migration is almost always disk I/O (IOPS). When you are replaying binary logs or restoring an InnoDB tablespace, you need queue depth.

Pro Tip: Latency matters. If your users are in Norway, your database should be in Norway. The round-trip time (RTT) from Oslo to Amsterdam is ~18ms. From Oslo to a local NIX-connected datacenter? <2ms. That 16ms difference compounds on every single SQL query.

At CoolVDS, we enforce KVM virtualization on pure NVMe arrays. We do this because "Noisy Neighbors" on shared spinning rust will kill your consistency checks. When you provision your target server, ensure it has at least double the IOPS capacity of your source server to handle the catch-up phase rapidly.

Phase 2: The Hot Backup Strategy

We are going to use Percona XtraBackup. Unlike mysqldump, which locks tables and exports logical SQL (slow), XtraBackup copies the physical InnoDB data files while the server is running. It's hot, it's consistent, and it's fast.

Step 1: Prepare the Source

On your current (Source) server, we need to ensure binary logging is enabled and the server ID is unique. Edit your /etc/mysql/my.cnf (or /etc/my.cnf depending on your distro, likely Ubuntu 18.04 or CentOS 7):

[mysqld]
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_format = ROW
expire_logs_days = 7
max_binlog_size = 100M
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1

If you changed these, a restart is required. If you cannot restart, you can set some of these globally at runtime, but log_bin requires a restart. Plan this once.

Step 2: Create the Replica User

We need a user for the target CoolVDS instance to connect back to the source to fetch updates.

CREATE USER 'replicator'@'%' IDENTIFIED BY 'Strong_Password_2018!';
GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%';
FLUSH PRIVILEGES;

Step 3: The Physical Snapshot

Install XtraBackup (version 2.4 is the standard for MySQL 5.7) and run the backup. We will stream this directly to the new server using xbstream and netcat to avoid writing to the local disk first. This saves space and time.

On the Target (CoolVDS) server:

nc -l -p 9999 | xbstream -x -C /var/lib/mysql/backup/

On the Source server:

innobackupex --stream=xbstream /tmp/ | nc target_server_ip 9999

This pipes the raw data over the network. Once finished, you must prepare the backup on the Target server to apply the transaction logs that occurred during the transfer.

innobackupex --apply-log /var/lib/mysql/backup/

Now, restore it to the data directory:

innobackupex --copy-back /var/lib/mysql/backup/
chown -R mysql:mysql /var/lib/mysql

Phase 3: establishing Replication

The backup contains a file called xtrabackup_binlog_info. This is your gold. It tells you the exact binary log file and position where the snapshot finished.

cat /var/lib/mysql/backup/xtrabackup_binlog_info
# Output example: mysql-bin.000003  4567

Now, configure the Target server (your new CoolVDS instance) to be a slave of the old server.

CHANGE MASTER TO
  MASTER_HOST='source_server_ip',
  MASTER_USER='replicator',
  MASTER_PASSWORD='Strong_Password_2018!',
  MASTER_LOG_FILE='mysql-bin.000003',
  MASTER_LOG_POS=4567;

START SLAVE;

Check the status immediately:

SHOW SLAVE STATUS\G

Look for Seconds_Behind_Master. It might start high, but on NVMe storage, this number should drop rapidly to 0. This is the "Catch-Up" phase.

Phase 4: The Cutover

At this point, you have two identical databases. The old one is live; the new CoolVDS one is updated in real-time. You can leave this running for days if you want to test read performance.

When you are ready to switch (The Maintenance Window):

  1. Put your application in "Maintenance Mode" (stops writes).
  2. Verify the slave has processed all events (Seconds_Behind_Master must be 0).
  3. Stop the slave: STOP SLAVE;
  4. Promote the Target to Master: RESET MASTER;
  5. Point your application config (.env file) to the new CoolVDS IP.
  6. Lift Maintenance Mode.

Total downtime? Usually about 30 to 60 seconds—just enough time to edit a config file and restart PHP-FPM or Nginx.

Optimizing for the Hardware

You migrated to CoolVDS to get better performance, so don't run default configs. The default MySQL 5.7 configuration is designed for 512MB RAM machines from 2010. You need to adjust your innodb_buffer_pool_size.

Server RAMRecommended Buffer PoolWhy?
4 GB2 GB - 2.5 GBLeave room for OS overhead.
16 GB10 GB - 12 GBMaximize cached data, reduce disk reads.
64 GB50 GBKeep entire dataset in RAM if possible.

Set this in your my.cnf immediately after migration. With NVMe backing your swap and storage, you can push these limits aggressively, but never starve the kernel.

Final Thoughts

Migration is not about hoping for the best; it's about replicating the state until the cost of switching is zero. By utilizing tools like XtraBackup and the sheer I/O throughput of CoolVDS's NVMe platform, you remove the risk of data corruption and the embarrassment of extended downtime.

Your data belongs in a secure, high-performance environment. Don't let legacy hardware hold your schema hostage. Spin up a CoolVDS instance today, configure your replication channel, and make the switch before your current disk queue depth hits the ceiling.