Surviving the Switch: Zero-Downtime Database Migration Strategies for Norwegian High-Traffic Sites
It is 3:00 AM. The coffee pot is empty. You are staring at a terminal window where a cursor blinks mockingly. You just tried to pipe a 500GB mysqldump over a flaky network connection to a new server, and it failed at 98%. Your CEO expects the new platform to be live by 8:00 AM.
We have all been there. Migration is the single most stressful event in a sysadmin's life. If you screw up the web server config, you restart Nginx. If you corrupt the database during a migration, you are looking at resume-generating downtime.
In 2016, with the sheer volume of data e-commerce stores are generating, the old "maintenance mode" strategy—where you shut down the site for four hours—is dead. You need zero downtime. Furthermore, with the recent invalidation of the Safe Harbor agreement and the looming shadow of new EU data regulations (GDPR is coming, folks), moving your data to a sovereign Norwegian host isn't just about latency; it's about legal survival.
Here is how we handle migrations at scale without melting the servers or losing a single transaction.
The Enemy: Latency and Locking
The naive approach involves mysqldump. For a 500MB database, fine. For 50GB? You are locking tables. While your dump runs, your customers can't checkout. If you are migrating a Magento store or a high-traffic Joomla site hosted in Oslo, table locks are unacceptable.
The second enemy is network latency. Transferring block-level data across the internet is slow. This is why we always recommend keeping infrastructure physically close. Hosting your database on a CoolVDS instance in Oslo while your app server is in Frankfurt is a recipe for I/O wait disasters. Keep them on the same switch, or at least the same country.
The Strategy: Replication-Based Migration
Do not move the database. Clone it, sync it, then switch it. We use Percona XtraBackup and standard MySQL replication. This allows the old server to stay live while the new server catches up.
Step 1: The Non-Blocking Backup
First, on your source server (let's assume CentOS 7 running MySQL 5.7 or MariaDB 10.1), install XtraBackup. Unlike mysqldump, this tool copies InnoDB data files directly, resulting in minimal locking.
# Install Percona repository
yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
yum install percona-xtrabackup-24
# Create a backup directory
mkdir -p /data/backups
# Run the backup
innobackupex --user=root --password=YOUR_PASSWORD --no-timestamp /data/backups/full_backup
This process takes a snapshot of your data. Crucially, it records the binary log position at the exact moment the backup finished. You will find this in the xtrabackup_binlog_info file.
Pro Tip: If you are migrating to a CoolVDS instance, ensure you are provisioning our NVMe-backed storage. Restoring a 100GB backup on spinning rust takes hours. On NVMe, it is a matter of minutes. Disk I/O is usually the bottleneck in restore operations.
Step 2: Prepare and Transfer
InnoDB data files are not consistent immediately after a copy. You must apply the transaction logs. Do this before you transfer to save CPU on the receiving end.
innobackupex --apply-log /data/backups/full_backup
Now, push it to your new CoolVDS server using rsync. We use screen so a dropped SSH connection doesn't kill the transfer.
screen -S migration
rsync -avzW --progress -e ssh /data/backups/full_backup root@185.x.x.x:/var/lib/mysql_new/
Step 3: Configure the New Master
On your new server, you need to configure my.cnf to handle the load. Do not just copy the old config. The hardware is likely different. If you are moving to our KVM platform, you have dedicated resources, so you can be aggressive with memory allocation.
Here is a baseline for a 16GB RAM instance:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Safety First
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
# Performance
innodb_buffer_pool_size = 10G
innodb_log_file_size = 1G
innodb_file_per_table = 1
# Replication Settings
server-id = 2
log_bin = /var/log/mysql/mysql-bin.log
relay_log = /var/log/mysql/mysql-relay-bin.log
read_only = 1
Note read_only = 1. This prevents accidental writes to the new server before you are ready.
Step 4: Enable Replication
Once the data is in place and the permissions are fixed (chown -R mysql:mysql /var/lib/mysql), start the service. Now, check the binlog coordinates from your source server backup.
cat /data/backups/full_backup/xtrabackup_binlog_info
# Output example: mysql-bin.000003 456789
On the new server (the slave), connect to the MySQL shell and set up the master:
CHANGE MASTER TO
MASTER_HOST='10.x.x.x',
MASTER_USER='replication_user',
MASTER_PASSWORD='secure_password',
MASTER_LOG_FILE='mysql-bin.000003',
MASTER_LOG_POS=456789;
START SLAVE;
Check the status with SHOW SLAVE STATUS \G. You want to see Seconds_Behind_Master: 0.
The Cutover
At this point, your new CoolVDS server is a perfect, real-time mirror of your production site. You can test it. Benchmark it. Run heavy SELECT queries against it to verify performance without impacting live users.
When you are ready to switch:
- Put the app in maintenance mode (for 30 seconds).
- Verify the slave has processed all events (
Seconds_Behind_Masteris 0). - Stop the slave:
STOP SLAVE; - Make it writable:
SET GLOBAL read_only = 0; - Point your application config (
wp-config.php,local.xml, etc.) to the new IP.
Why Local Matters
We are seeing more Norwegian clients migrate away from US-based giants back to local infrastructure. The latency benefit is obvious—pinging a server in Oslo from Oslo takes 1-2ms, versus 30ms+ to Amsterdam or 100ms to Virginia. In the database world, where a single page load might generate 50 queries, that latency adds up to seconds of delay.
But beyond speed, there is compliance. Datatilsynet is watching. Hosting your customer data within Norwegian borders on a provider like CoolVDS ensures you aren't caught in the crossfire of international data privacy wars. We own our hardware. We control the network. Your data stays here.
Final Thoughts
Migrations don't have to be gambles. By using replication, you remove the "point of no return." If the new server acts up during the sync phase, you just cancel the operation. No harm done.
Don't let slow I/O kill your SEO or your sanity. If you need a staging environment to test this replication strategy, deploy a high-performance KVM instance on CoolVDS today. We spin them up in 55 seconds.