Console Login

Zero-Downtime Database Migration: A Sysadmin’s Guide to Norwegian VPS Success

Zero-Downtime Database Migration: A Sysadmin’s Guide to Norwegian VPS Success

There are two types of systems administrators in this world: those who have lost data during a migration, and those who verify their checksums. If you are reading this, you are likely planning to move a production database—perhaps a heavy Magento 1.7 store or a high-traffic Drupal backend—and the thought of mysqldump locking your tables for three hours makes you sweat.

It should.

Downtime is expensive. In the Norwegian e-commerce sector, downtime during peak hours isn't just lost revenue; it's a reputation killer. Clients expect local speeds, and if your database is stuck in an I/O bottleneck during a transfer, your frontend Time-To-First-Byte (TTFB) tanks.

In this guide, we are not doing a "pray and switch" migration. We are performing a live Master-Slave replication setup to transition data from an old legacy host to a high-performance VPS Norway instance on CoolVDS. We will use Percona XtraBackup and standard tools available on CentOS 6.4.

The Architecture of a Safe Migration

The naive approach is to shut down the web server, dump the database, transfer it, import it, and switch DNS. This works for a personal blog. It does not work for business.

The professional approach leverages MySQL's built-in replication. We treat the new CoolVDS server as a "Slave" to the current "Master." Once the slave catches up (0 seconds behind master), we promote the slave to master and switch the application config. Downtime is reduced from hours to the seconds it takes to edit a config.php file.

Prerequisites

  • Source Server (Master): MySQL 5.5+, accessible via SSH.
  • Destination Server (Slave): CoolVDS Instance (CentOS 6 / Debian 7), MySQL 5.5+.
  • Network: Low latency is critical. If your audience is in Oslo, hosting in Frankfurt adds unnecessary milliseconds.

Step 1: Preparing the Master

First, ensure your current server is ready to replicate. You need binary logging enabled. Check your /etc/my.cnf (or /etc/mysql/my.cnf on Debian/Ubuntu).

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

Pro Tip: Setting sync_binlog = 1 is the safest for data integrity (ACID compliance), though it hits disk I/O hard. On standard spinning rust (HDD), this hurts. On CoolVDS's SSD storage arrays, the latency penalty is negligible.

Create a replication user. Do not use root.

mysql -u root -p

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

Step 2: The Non-Blocking Snapshot

Don't use mysqldump. It locks MyISAM tables and can cause performance degradation on InnoDB. We use Percona XtraBackup (specifically innobackupex). It copies InnoDB data files while the database runs, without locking it.

Install it on the Master:

rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
yum install percona-xtrabackup

Run the backup:

innobackupex --user=root --password=YOURPASS /var/tmp/mysql_backup/

Step 3: Transfer to CoolVDS

Now we move the data. We use rsync because it’s robust and resumable. We also want bandwidth compression because even with fast pipes, we don't want to saturate the link.

rsync -avzP /var/tmp/mysql_backup/ root@new-coolvds-ip:/var/tmp/mysql_backup/

While this transfers, let's talk about low latency. Distance matters. If your customer base is Norwegian, the round-trip time (RTT) for every TCP packet handshake counts. Hosting on a local node in Norway or nearby Northern Europe ensures that your SSH sessions are snappy and your database queries don't hang.

Step 4: Prepare and Restore on Slave

On the new CoolVDS server (the Slave), stop MySQL.

service mysqld stop
rm -rf /var/lib/mysql/*

Prepare the backup (apply transaction logs) and restore it. This makes the data consistent.

# Prepare
innobackupex --apply-log /var/tmp/mysql_backup/2013-08-20_12-00-00/

# Restore
innobackupex --copy-back /var/tmp/mysql_backup/2013-08-20_12-00-00/

# Fix permissions
chown -R mysql:mysql /var/lib/mysql

Step 5: Start Replication

Look at the file xtrabackup_binlog_info inside the backup directory. It contains the coordinates you need.

cat /var/tmp/mysql_backup/2013-08-20_12-00-00/xtrabackup_binlog_info
# Output example: mysql-bin.000003  4567

Configure the new server's my.cnf with a unique server-id (e.g., server-id = 2) and start MySQL.

Now, link them up:

CHANGE MASTER TO
MASTER_HOST='old-server-ip',
MASTER_USER='replicator',
MASTER_PASSWORD='StrongPassword123!',
MASTER_LOG_FILE='mysql-bin.000003',
MASTER_LOG_POS=4567;

START SLAVE;

Check the status:

SHOW SLAVE STATUS\G

You are looking for Slave_IO_Running: Yes and Slave_SQL_Running: Yes. If Seconds_Behind_Master is decreasing, you are winning.

Why Hardware Dictates Stability

I recently consulted for a client moving away from a budget VPS provider. Their database kept crashing under load. The issue wasn't CPU; it was "noisy neighbors" and poor disk I/O throughput. In virtualized environments (like OpenVZ or badly managed Xen), if another user on the host node hits the disk hard, your database waits.

The CoolVDS Difference: We use KVM virtualization to ensure strict resource isolation. More importantly, we are deploying high-performance PCIe SSD storage. For database workloads involving heavy random R/W operations, spinning disks are obsolete. The low latency of solid-state storage is the single biggest upgrade you can give your database.

Legal Compliance: The Norwegian Context

We cannot ignore the Personopplysningsloven (Personal Data Act). The Data Protection Authority (Datatilsynet) is strict about where and how personal data is stored. By utilizing managed hosting solutions with infrastructure located within the EEA (and ideally Norway), you simplify compliance significantly compared to utilizing US-based clouds subject to the Patriot Act.

The Cutover

Once the slave is caught up:

  1. Put your web app in maintenance mode (5 minutes max).
  2. Stop writing to the Master.
  3. Verify the Slave has processed all logs (Seconds_Behind_Master: 0).
  4. Promote the Slave to Master (Stop Slave, Reset Master).
  5. Point your app config to the new CoolVDS IP.

Also, don't forget ddos protection. A new IP address is a fresh target. Ensure your firewall (iptables or CSF) is configured immediately upon deployment.

Database migration doesn't have to be a gamble. With the right tools and solid hardware backing you up, it’s just another Tuesday.

Ready to stop waiting on I/O wait? Deploy a KVM instance with pure SSDs on CoolVDS today and see what raw performance looks like.