ARTICLEisayeter.com11 min read

Seamless Migration from DigitalOcean to Hetzner: A Cost-Effective Strategy

Seamless Migration from DigitalOcean to Hetzner: A Cost-Effective Strategy

AI Summary

Faced with escalating costs due to inflation and currency devaluation in Turkey, I decided to migrate our infrastructure from DigitalOcean to Hetzner. Our monthly bill for a DigitalOcean droplet with 192GB RAM, 32 vCPUs, and 600GB SSD was $1,432, which was unsustainable. In contrast, Hetzner offered a more powerful server with 256GB DDR5 RAM and 1.92 TB NVMe storage for just $233 a month, saving us $14,388 annually.

## Migration Strategy

The migration involved moving 248 GB of MySQL data across 30 databases, 34 Nginx sites, GitLab EE, and Neo4j, all while maintaining zero downtime. We meticulously planned the migration in six phases, starting with setting up the full stack on the new server, including Nginx, PHP, MySQL 8.0, and more. SSL certificates were transferred using rsync, and web files were cloned with integrity checks.

## MySQL Replication

The most challenging part was the MySQL migration. We used mydumper for parallel data export, significantly reducing the time required. Live replication was set up, with the old server as master and the new one as a read-only slave, ensuring real-time sync until cutover. We overcame issues like duplicate key errors by setting the slave_exec_mode to 'IDEMPOTENT'.

## DNS and Nginx Configuration

To ensure seamless DNS transition, we reduced TTLs and used a Python script to convert old server Nginx configurations into reverse proxies pointing to the new server. This allowed for uninterrupted service during DNS propagation.

## Final Steps and Results

After thorough testing, we executed the cutover, ensuring all services were operational on the new server. Post-migration, we updated GitLab webhooks to the new IP. The migration was completed in 24 hours with zero downtime, providing a more powerful setup at a fraction of the cost.

## Key Takeaways

MySQL replication is crucial for zero-downtime migrations. Checking user privileges is essential, as SUPER privilege can bypass read-only settings. Scripting repetitive tasks minimizes errors and saves time. Finally, dedicated servers can offer better performance and cost savings compared to cloud providers for steady-state workloads.

Key Concepts

Infrastructure Migration

The process of moving data, applications, and workloads from one IT environment to another, often to improve performance, reduce costs, or enhance security.

Cost Optimization

Strategies and practices aimed at reducing expenses while maintaining or improving service quality and performance.

Category

Technology
M

Summarized by Mente

Save any article, video, or tweet. AI summarizes it, finds connections, and creates your to-do list.

Start free, no credit card