Note that the method below only shows how to save personal data and how to copy it to the new server. To migrate an entire partition, see "Migrate partitions from another provider to Hetzner".
To migrate from a server with another provider to a Hetzner, follow these steps:
-
Connect to your old server and create a backup.
Before you create the backup, make sure the service is not being used. Otherwise, any new data might be saved as you create the backup or after you created it. This data will then be missing in the backup.
Create a new directory, such as
~/backupsand save all the backups you need to migrate within that directory. This example usestarto create the backups.
-
Save users, their permissions, and their
~/.sshdirectories.You need to run these commands as root user.
Replace/home/holu/with the path of the user that created the backup directory.sudo su cd /etc && sudo tar -czvf /home/holu/backups/users-and-permissions.tar.gz -P passwd group shadow sudoers sudo tar czvf /home/holu/backups/ssh-directories.tar.gz $(find /home -maxdepth 3 -type d -name ".ssh") exit
-
Save firewall rules.
For example
iptables:sudo iptables-save > ~/backups/iptables_backup.txt sudo ip6tables-save > ~/backups/iptables6_backup.txt
- Save your personal data:
sudo tar -cvzf ~/backups/example-dir.tar.gz /file/or/directory/to/save
If you need to migrate any additional data (for example, a database dump), create a backup of that too and save it in the
~/backupsdirectory. -
-
Create a new SSH key on your old server that you can use for the migration.
ssh-keygen -t ed25519 -f ~/.ssh/migrate-backupsNow copy the new public SSH key.
-
Create a new server on Hetzner Console.
» Getting Started: Creating a Server
-
Connect to the new server.
Edit
~/.ssh/authorized_keyand add the public key you just created on the old server for the migration process (~/.ssh/migrate-backups.pub).nano ~/.ssh/authorized_keys
-
Connect to the old server again.
Now that the public SSH key of the old server is saved on the new server, you should be able to copy the backup directory to the new server via SSH.
Replace
203.0.113.1with the IP address of the new Hetzner Cloud server.scp -i ~/.ssh/migrate-backups -r ~/backups root@203.0.113.1:~/
-
Next, connect to the new Hetzner Cloud server.
The server should now also have the
~/backupsdirectory with all the backup files. Example:root@new-server:~/backups# ls example-dir.tar.gz iptables6_backup.txt iptables_backup.txt users-and-permissions.tar.gz ssh-directories.tar.gzExtract the backups for the users, their permissions and the SSH settings:
tar -xvf ~/backups/users-and-permissions.tar.gz -C /etc tar -xzvf ~/backups/ssh-directories.tar.gz -C /Now set up your server (for example, set up a firewall, install any required software, ...)
iptables-restore < ~/backups/iptables_backup.txt ip6tables-restore < ~/backups/iptables6_backup.txtAfter the server is set up and any required software was installed, extract your personal data:
Replace
/target/directorywith the target path.tar -xvf ~/backups/example-dir.tar.gz -C /target/directory
The new server should be ready to go, and your data should be available. If you have a domain, remember to update your DNS records with the new IP address. Before you delete the old server, verify that all data was migrated successfully, and make sure everything is working as expected.