Migrating MySQL to Aurora: why I took AWS DMS back out

I planned a MySQL to Aurora migration around AWS DMS and removed it after the first rehearsal. What went wrong, how XtraBackup, an S3 restore and binlog replication saved the cutover and when DMS is still the right call.

Tomislav PreeAWS Cloud Architect from Mainz
December 3, 20268 min read
Contents
  1. Key takeaways
  2. What happened in the DMS rehearsal
  3. The second attempt: physical backup and binlog replication
  4. When DMS is still the right call
  5. What I do differently today
  6. Frequently asked questions

Key takeaways

  • For MySQL to Aurora MySQL, AWS DMS is usually the wrong tool because source and target run the same engine.
  • In limited LOB mode DMS truncates long TEXT and JSON columns and only logs a warning.
  • DMS creates only tables and primary keys on the target, so indexes, defaults and foreign keys are missing.
  • Percona XtraBackup, a restore from S3 and binlog replication give you the identical schema and a cutover with a few minutes of write downtime.
  • A cutover date is only set once the way back via replication from Aurora to the old database has been rehearsed.

After two days the plan looked clean on the whiteboard. A SaaS client ran a self-managed MySQL 8.0 database in a colocation data center, close to a terabyte of data, serving customers in several time zones around the clock. The target was Aurora MySQL in Frankfurt with at most a few minutes of write downtime. The tool of choice was AWS Database Migration Service, full load plus change data capture, the way it gets shown in a lot of workshops.

Three weeks later I took DMS out of the project. We did the migration with Percona XtraBackup, a restore from S3 and plain MySQL binlog replication. This article covers what went wrong in the rehearsal, what the second approach looked like and when DMS is still the right tool.

What happened in the DMS rehearsal

Before any database migration I run at least one full rehearsal against a copy of production. On this project that rehearsal is where the workshop assumptions fell apart.

Truncated columns without an error

The application stored configuration and audit entries as JSON in TEXT and JSON columns. DMS treats those as LOBs and defaults to limited LOB mode. Anything above the configured max LOB size gets cut off, and DMS only writes a warning to the task log. The task itself finishes green.

We noticed because the application crashed on broken JSON while loading some customer configurations during the rehearsal. The fix is well known: measure the maximum LOB length per column and set the limit to match, or switch to full LOB mode. AWS itself documents that values above 63 KB slow down full load noticeably, and full LOB mode is slower still. On a table with several hundred million rows that was the difference between one night and several days.

Tables without indexes, defaults and foreign keys

The second issue is in the documentation, but people skim past it. DMS creates only what it needs to copy the data on the target: tables and in most cases the primary key. Secondary indexes, default values, foreign keys, triggers, stored procedures and users are missing.

The usual workaround is to create the schema up front with mysqldump --no-data and enable foreign keys and indexes only after the full load, because DMS loads tables in no particular order. It works, but it turns a migration into a small software project with its own failure modes. Forget to recreate one index after the full load and you find out under production load.

A tool for a problem we did not have

The real mistake was mine. DMS is built for migrations where source and target differ: Oracle to PostgreSQL, SQL Server to Aurora, subsets of tables into a new schema. We had MySQL 8.0 on one side and Aurora MySQL 3, which is MySQL 8.0 compatible, on the other. AWS itself recommends native database tools when the engine stays the same. I had picked DMS because it felt like "the AWS way", not because the case called for it.

The second attempt: physical backup and binlog replication

The new plan had four steps, and each one can be tested and repeated on its own.

Four steps from MySQL in the data center to Aurora, with a tested way back after cutoverOpen diagram in a new tab

Step 1: prepare the binlog and take the backup

The source needs binlogs enabled in ROW format and a retention period longer than backup, upload, restore and catch-up combined. We set binlog_expire_logs_seconds to seven days for the duration of the migration. That cost some disk space and gave us room to repeat a restore if needed.

The backup runs while production keeps running, because XtraBackup copies InnoDB data without a global lock. MySQL 8.0 needs XtraBackup 8.0, MySQL 5.7 needs version 2.4. We split the stream into 500 MB parts and uploaded them to S3:

xtrabackup --backup --user=backup --password="$BACKUP_PW" \
  --stream=xbstream --target-dir=/tmp/xb \
  | split -d --bytes=500MB - /backup/full.xbstream.

aws s3 cp /backup/ s3://client-db-migration/full/ --recursive

The file xtrabackup_binlog_info inside the backup matters most. It holds the binlog file and position at backup time, which is exactly where Aurora has to start catching up later.

Step 2: restore the Aurora cluster from S3

The restore creates a new Aurora cluster straight from the backup files. The bucket has to be in the same region, and RDS needs an IAM role with read access to the prefix:

aws rds restore-db-cluster-from-s3 \
  --db-cluster-identifier app-aurora \
  --engine aurora-mysql \
  --master-username admin --manage-master-user-password \
  --source-engine mysql --source-engine-version 8.0.36 \
  --s3-bucket-name client-db-migration --s3-prefix full \
  --s3-ingestion-role-arn arn:aws:iam::111122223333:role/rds-s3-import \
  --db-subnet-group-name db-private --vpc-security-group-ids sg-0abc123 \
  --storage-encrypted

Then aws rds create-db-instance adds the writer instance to the cluster. The physical restore was many times faster than the logical full load in the DMS rehearsal, and above all the schema arrived exactly as it was: indexes, defaults, foreign keys, character sets.

Two things do not come along. User accounts and stored routines have to be moved separately. We recreated the users anyway, because the application moved to IAM authentication and Secrets Manager as part of the project, and we exported the routines with mysqldump --routines --no-create-info --no-data.

Step 3: let Aurora catch up as a replica

Now Aurora attaches to the old database via binlog replication and replays everything that happened after the backup. The connection ran over a site-to-site VPN with TLS on the replication channel:

mysql -h app-aurora.cluster-xyz.eu-central-1.rds.amazonaws.com -u admin -p -e "
  CALL mysql.rds_set_external_source('10.20.0.15', 3306, 'repl', '$REPL_PW',
       'binlog.000412', 15738213, 1)"

mysql -h app-aurora.cluster-xyz.eu-central-1.rds.amazonaws.com -u admin -p -e "
  CALL mysql.rds_start_replication"

On Aurora MySQL 2 the procedures are still called rds_set_external_master. You track progress with SHOW REPLICA STATUS\G in the Seconds_Behind_Source field. After the restore Aurora was a few hours behind and had caught up overnight.

From here we had what DMS had promised: a live target a few seconds behind production. Only with the identical schema and without columns that end somewhere around 64 KB. For a week the application ran read-only against Aurora in a staging environment, so we could check query plans and latency on real data.

Step 4: cutover with a way back

For the switch itself I have a fixed rule: no cutover without a tested way back. So we enabled binlogs on Aurora beforehand (binlog_format = ROW in the cluster parameter group, which needs a reboot) and rehearsed running the old database as a replica of Aurora after the switch.

The maintenance window went like this:

  1. Lower the TTL of the internal Route 53 record to 60 seconds two days ahead.
  2. Set the source to super_read_only = ON, so the application stops writing.
  3. Wait until Seconds_Behind_Source is 0 and the positions match on both sides.
  4. Run CALL mysql.rds_stop_replication and CALL mysql.rds_reset_external_source on Aurora, then point the DNS record at the cluster endpoint.
  5. Start the old database as a replica of Aurora, so every new write also lands there.

Write downtime stayed under five minutes, and most of it was the application's connection pools picking up the new DNS record. The old database kept running as a replica for two more weeks before we shut it down. We never needed the way back, but without it I would not have agreed to the date.

When DMS is still the right call

I do not want to talk DMS down. There are cases where I use it without hesitation:

  • Source and target are different engines, for example Oracle or SQL Server to Aurora PostgreSQL, together with the Schema Conversion Tool.
  • You migrate only some tables, filter rows or merge several databases into one.
  • The source is another provider's managed service where you cannot take a physical backup but do get binlog access.
  • You want to stream changes into another system permanently, for example into S3 or Kinesis.

If the source already runs on RDS for MySQL, the shortest path is usually an Aurora read replica created directly from the RDS instance, with no backup files at all.

What I do differently today

For MySQL to Aurora I now always start with the physical path and justify it when I deviate. The rehearsal against a production copy stays mandatory whatever the tool, and the rehearsal includes a data comparison. Row counts per table are not enough, so we also check checksums on samples and the maximum length of every text and JSON column.

The lesson for me was to derive the tool from the problem and not from a feeling of what is usual on AWS. A homogeneous migration is at its core a replication problem, and MySQL has solved replication on its own for more than twenty years. If you are facing a migration like this and want to know which path fits your database, we can work it out together in a short call.

Frequently asked questions

Can you migrate MySQL to Aurora without downtime?

Almost. With binlog replication Aurora runs as a replica of the old database until the switch and stays seconds behind. Write downtime is limited to setting the source read-only, applying the last transactions and switching DNS, which takes a few minutes in practice.

When should you use AWS DMS for a database migration?

DMS fits when source and target are different engines, for example Oracle to Aurora PostgreSQL, or when you migrate only part of the data, filter rows or merge databases. For the same engine AWS itself recommends the database's native tools.

Which XtraBackup version do I need to restore into Aurora?

MySQL 8.0 needs Percona XtraBackup 8.0 and MySQL 5.7 needs version 2.4. The S3 bucket has to be in the same region as the Aurora cluster. User accounts and stored routines are not restored and have to be moved separately.

How does a rollback work after switching to Aurora?

Enable binlogs on Aurora through the cluster parameter group before the cutover. After the switch the old database keeps running as a replica of Aurora and receives every new write. If something goes wrong you point the DNS record back without losing data.

Sources

  1. AWS DMS: Setting LOB support for source databases in a task
  2. AWS Knowledge Center: What objects can I migrate using an AWS DMS task?
  3. Best practices for AWS Database Migration Service
  4. Aurora: Physical migration from MySQL by using Percona XtraBackup and Amazon S3
  5. Aurora: Configuring, starting, and stopping binary log (binlog) replication
  6. Aurora: Replication between Aurora and MySQL (binary log replication)
Tomislav Pree

Tomislav Pree

Cloud Architect based in Mainz, building AWS platforms and writing about GitOps, Kubernetes, and MLOps.