AWS RDS Migration
Background
- To optimize operational expenses compared to maining on-premises data centers.
- AWS RDS offers robust security features and compliance with stringent regulatory requirements, critical for banks.
I. Pre-Migration Preparation Phase
-
Data Volume Assessment
-
Access Data Size
SELECT table_schema, SUM(data_length)/1024/1024 AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema; -
Estimate Migration Time
- Use AWS Network Manager to test dedicated/public network bandwidth and calculate migration time.
-
Create Priority Matrix:
- Low Priority: Log tables, historical archive data (migrate first).
- High Priority: Core user data, transaction tables (migrate last).
- Disabled: Temporary tables, test data (may not be migrated).
-
-
Full Backup and Rollback Preparation
- Local Backup: Perform a full backup of the source database.
mysqldump --single-transaction --master-data=2 -u root -p dbname > full_backup.sql
- RDS Initial Backup: Create an initial backup for the RDS instance.
CALL mysql.rds_set_configuration('binlog_retention_hours', 24)
- Rollback Snapshot: Use AWS Backup service to create a manual snapshot of the RDS instance.
- Local Backup: Perform a full backup of the source database.
-
Enterprise
II. Migration Execution Phase
- AWS DMS Migration Process
- Advantages:
- CDC (Continuous Data Replication): Achieves
<3
seconds level delay - Automatically handle schema conversion: CHAR -> VARCHAR
- Built-in data validation function (by enabling
validation=enable
)
- CDC (Continuous Data Replication): Achieves
- Migration Configuration:
Task Settings Example
{
"TargetMetadata": {
"ParallelLoadThreads": 16, // Adjust based on instance specifications
"LobChunkSize": 64 // Optimize BLOB field transmission
},
"TTSettings": {
"EncryptionMode": "SSE_KMS", // Enable KMS encryption
"SecurityProtocol": "SSL" // Transport layer encryption
}
}
- Advantages:
- Phased Migration Control
- Phase 1: Migrate non-core tables (logs/historical data)
- Use DMS full load (do not enable CDC)
- Phase 2: Migrate core business tables
- Full load + incremental synchronization mode
- Set
maxFullLoadSubTasks=8
to improve throughput
- Phase 3: Migrate system tables (users/privileges)
- Manually export permission statements
SELECT CONCAT('SHOW GRANTS FOR ''',user,'''@''',host,''';') FROM mysql.user;
- Phase 1: Migrate non-core tables (logs/historical data)
III. Data Consistency Assurance
- Integrity Check
- DMS Built-in Validation:
aws dms start-replication-task-assessment-run
- Custom Validation Script:
# Source-side Statistics
src_count = execute("SELECT COUNT(*) FROM orders WHERE date > '2023-01-01'")
# Target-side Statistics
tgt_count = rds_execute("SELECT COUNT(*) FROM orders WHERE date > '2023-01-01'")
assert src_count == tgt_count
- DMS Built-in Validation:
- Index and Performance Verification
- Index Validation:
-- Check for Missing Indexes
SELECT t.table_name
FROM information_schema.tables t
LEFT JOIN information_schema.statistics s
ON t.table_name = s.table_name
WHERE t.table_schema = 'prod_db'
AND s.index_name IS NULL; - Performance Benchmark Testing
- Use sysbench to perform TPC-C equivalent tests
- Compare p99 query latency before and after migration
- Index Validation:
IV. Post-Migration Switchover Phase
- Final Data Synchronization
- Execute Downtime Window (Recommended during business off-peak period):
- Stop application writes
- Execute DMS final CDC synchronization (wait for lag to zero)
- On RDS, execute
FLUSH LOGS
and record binlog position
- Execute Downtime Window (Recommended during business off-peak period):
- Traffic Switchover Validation
- Use Route53 weighted routing to gradually switch traffic (10%→100%)
- Real-time monitoring of RDS performance metrics:
WriteIOPS
,CPUUtilization
,ReplicaLag
- Enable Enhanced Monitoring for fine-grained monitoring
V. Rollback Plan
- Quick Rollback Trigger Conditions
- RDS write latency continuously >5 seconds
- Data inconsistency records >0.001%
- Key business interface error rate >1%
- Rollback Operation Process
- Switch back to local MySQL
mysql -h localhost -u root -p dbname < final_backup.sql
- Clean up RDS residual data:
DROP DATABASE IF EXISTS prod_db;
CREATE DATABASE prod_db CHARACTER SET utf8mb4;
- Switch back to local MySQL
VI. Security and Monitoring
- Encryption Implementation
- Transmission Encryption: DMS task forces SSL connection
- Static Encryption: RDS enables KMS CMK encryption
- Key Rotation: Through KMS automatic key rotation policy
- Monitoring Alarm Configuration
- CloudWatch Alarm Settings:
FreeStorageSpace < 20GB
BinLogDiskUsage > 80%
- Configure EventBridge Events:
- Automatically trigger Lambda for daily data sampling validation
- CloudWatch Alarm Settings: