Migrating from Hetzner to another hosting provider without downtime is possible by using a combination of meticulous planning, step-by-step data synchronization via rsync, and smart DNS management, allowing traffic to be switched to the new server smoothly and imperceptibly for end-users. This process requires attention to detail, but with the right approach, it guarantees the continuous operation of your services.
Why Users Decide to leave Hetzner?
Hetzner Online is a well-known and respected hosting provider, offering competitive prices and reliable infrastructure. However, even such a giant has its peculiarities that may not suit all users. The decision to leave Hetzner is often dictated by several key factors:
- Support: While Hetzner provides basic support, it is often limited to hardware and network-related issues. For tasks requiring deep dives into software or configuration, users may seek a provider with more extensive and responsive technical assistance.
- Flexibility and Customization: Some users require more flexible server settings, specific operating systems, or custom configurations that may be limited or less available with Hetzner.
- Geographical Location: Hetzner's main data centers are located in Germany and Finland. For projects targeting audiences in other regions, such as North America or Asia, a server located closer to the target audience may be required to reduce latency.
- DDoS Protection and Security: While Hetzner offers basic protection, advanced or specialized solutions for DDoS attack protection and other security threats may be a higher priority for some projects.
- Pricing Policy: Despite Hetzner's attractive prices, users sometimes find that for their specific requirements (e.g., high I/O performance or specific licenses), other providers offer more favorable terms or a better balance of price and quality.
Preparing for Hetzner migration: What to Consider?
A successful Hetzner migration begins long before files are copied. Thorough preparation is the key to avoiding problems and downtime. Here's what you need to consider:
- Inventory of the Current Server: Compile a complete list of everything running on your current Hetzner server. This includes:
- Operating system and its version.
- Web server (Apache, Nginx, LiteSpeed) and its configuration.
- Databases (MySQL, PostgreSQL, MongoDB, Redis) and their versions.
- Programming languages (PHP, Python, Node.js, Ruby) and their versions, modules used.
- Mail servers (Postfix, Exim), FTP servers, DNS servers.
- Task schedulers (cron jobs).
- SSL certificates and their paths.
- Any third-party applications, control panels (cPanel, Plesk, ISPmanager).
- Data size (files, databases) — this will help estimate synchronization time and choose the appropriate disk space on the new server.
- Choosing a New Hosting Provider and Server: Determine the requirements for the new server. Do you need a VPS or a dedicated server? What amount of RAM, number of CPU cores, type and size of disk (NVMe, SSD) do you need?
- Dependency Analysis: Ensure that all components of your application (PHP versions, Python libraries, etc.) will be compatible with the new environment. Sometimes software updates are required.
- Testing Plan: Develop a testing strategy to ensure that all services are working correctly on the new server before switching DNS.
- Migration Schedule: Choose the least busy time to start the migration to minimize potential impact on users if something goes wrong.
Step-by-Step Migration from Hetzner: Action Plan
Choosing a New Server: What to Pay Attention To?
The first and one of the most important steps is choosing the right infrastructure. When choosing, consider:
- Processor (CPU): For high-load applications, choose servers with more cores and a high clock speed, such as Intel Xeon E-series or AMD EPYC processors, ensuring excellent performance.
- Random Access Memory (RAM): Determine the required amount of RAM. For most web applications and databases, at least 4-8 GB is recommended. For large projects and high-load databases, 16 GB or more may be required.
- Disk Subsystem: Consider using NVMe drives, which are 5-10 times faster than regular SSDs. This is critically important for databases, file servers, and applications that heavily interact with the disk.
- Network Bandwidth: Ensure that the new server has sufficient bandwidth for your traffic, such as 1 Gbps or 10 Gbps ports.
- Support: Look for technical support ready to assist with installation, configuration, and even the migration process itself.
For clarity, let's look at typical Hetzner configurations:
| Characteristic | Hetzner Cloud CX21 (example) |
|---|---|
| vCPU | 2 (Intel Xeon) |
| RAM | 4 GB |
| Disk | 40 GB NVMe |
| Bandwidth | 200 Mbps |
| DDoS Protection | Basic |
| Tech Support | Basic |
| Estimated Price | €6.90 / month |
*Prices and characteristics may vary, provided for example.
Creating a Data Backup: Your Insurance
Before starting any migration, it is crucial to create a full backup of all data on your current Hetzner server. This is your insurance against unforeseen problems.
For databases (e.g., MySQL/MariaDB):
mysqldump -u root -p --all-databases > all_databases.sql
Or for a specific database:
mysqldump -u username -p database_name > database_name.sql
For files:
tar -czvf /root/full_backup_$(date +%F).tar.gz --exclude=/dev --exclude=/proc --exclude=/sys --exclude=/tmp --exclude=/run --exclude=/mnt --exclude=/media --exclude=/lost+found /
Save this backup in a secure location, preferably on external storage, separate from both servers.
Data Synchronization with rsync: The Key to Downtime-Free Migration
rsync is a powerful tool for incremental file synchronization that helps minimize downtime. The process consists of several stages:
- Initial Synchronization: Copy all files from Hetzner to the new server. This can take a significant amount of time depending on the data volume.
- Database Synchronization: After the initial file synchronization, transfer the databases. First, export them on the old server, then import them on the new one.
- Incremental Synchronizations: As you continue to work on the old server, keep running
rsync. This will only copy changed files, which is significantly faster.
rsync -avzP --exclude='/dev/*' --exclude='/proc/*' --exclude='/sys/*' --exclude='/tmp/*' --exclude='/run/*' --exclude='/mnt/*' --exclude='/media/*' --exclude='/lost+found/*' / root@ВАШ_НОВЫЙ_IP_VALEBYTE:/
Note: Replace ВАШ_НОВЫЙ_IP_VALEBYTE with the IP address of your new server. Options: -a (archive mode), -v (verbose output), -z (compression), -P (show progress and resume interrupted transfers).
# On the old server (Hetzner)
mysqldump -u root -p --all-databases > all_databases.sql
# Copy the file to the new server (Valebyte)
scp all_databases.sql root@ВАШ_НОВЫЙ_IP_VALEBYTE:/root/
# On the new server (Valebyte)
mysql -u root -p < all_databases.sql
rsync -avzP --exclude='/dev/*' --exclude='/proc/*' --exclude='/sys/*' --exclude='/tmp/*' --exclude='/run/*' --exclude='/mnt/*' --exclude='/media/*' --exclude='/lost+found/*' / root@ВАШ_НОВЫЙ_IP_VALEBYTE:/
Configuring and Testing the New Server
Once the data has been copied, you need to configure the new server so that it is fully ready for operation:
- Software Installation and Configuration: Install and configure the web server (Nginx, Apache), PHP, databases (MySQL, PostgreSQL), mail servers, and other necessary applications according to your inventory.
- Application Configuration: Update your application's configuration files to point to local databases and other resources.
- SSL Certificates: Install SSL certificates.
- Testing Without DNS Changes: To test the website on the new server before switching DNS, you can temporarily modify the
hostsfile on your local computer or use a proxy server. Add a line like:ВАШ_НОВЫЙ_IP yourdomain.com [www.yourdomain.com](https://www.yourdomain.com)This will allow your computer to access the new server by domain name, while other users still see the old Hetzner server. Thoroughly check all website functions, forms, admin panels, etc.
DNS Switchover and Finalization: How to switch from Hetzner?
This is the most critical moment when you finally switch from Hetzner to the new server.
- Reduce DNS Record TTL (Time To Live): 24-48 hours before the switch, change the TTL for your A-records (and possibly CNAMEs) to a minimum value, for example, 300 seconds (5 minutes). This will speed up the propagation of DNS changes.
- Stop Data Writing on the Old Server: If possible, put your website into maintenance mode or stop all processes that write data to the database or file system on the old Hetzner server.
- Final Synchronization: Perform the last
rsynccommand. Since the data is already almost identical, this will only take a few seconds or minutes. - Import Final Data: If there were changes in the databases, perform a final dump and import.
- Change DNS Records: In your domain registrar's control panel (or DNS provider), change the domain's A-records to point to the IP address of your new server.
- Monitoring: Over the next hours and days, carefully monitor the new server's logs, performance, and website availability. Ensure that traffic is being redirected correctly.
- Delete the Old Server: Once you are sure that everything is working stably on the new server and the old Hetzner server is no longer receiving traffic, you can safely shut it down and delete it.
Recommendations for a Successful Migration from Hetzner
To ensure your migration from Hetzner is as smooth and successful as possible, follow these recommendations:
- Thorough Testing: Never neglect testing. Check every function, every page, every integration on the new server before switching DNS.
- Communication: If your website has a large audience, consider notifying users about the upcoming migration, especially if a short maintenance window is expected.
- Monitoring: Use monitoring tools (Prometheus, Grafana, Zabbix) to track the performance and availability of both servers before, during, and after the migration.
- Documentation: Document every step of the migration, including all commands, configurations, and changes. This will help in case of a rollback or future migrations.
- Start Small: If you have multiple services, consider migrating the least critical service first to practice the process.
- Use SSH Keys: For secure and convenient access to servers when working with
rsyncandscp, always use SSH keys instead of passwords. - Check Firewall: Ensure that the firewall on the new server is configured correctly and does not block necessary ports for your application (HTTP, HTTPS, SSH, MySQL, etc.).
Conclusion
Migrating from Hetzner to a new hosting provider without downtime is an achievable goal with meticulous planning and the use of proven methodologies, such as incremental rsync synchronization and thoughtful DNS management, ensuring a smooth and secure transfer of your projects.