Hetzner is a nice, cheap host for server. Unfortunately they do not let you download backups and snapshots of cloud servers locally. So you are kind of locked in with them.
Here is how I create full disk backups for e.g. standard CX11 servers with default images.
Make sure you understand everything before you attempt this. Pay special attention to your own partitions and make sure you archive what you really need. Consider imaging the whole device instead of just a partition.
Create a backup
- Create a new snapshot of your server
- Create a new server from it
- Boot said server in rescue mode
- Use good old
dd
andgzip
to image the main disk to a local archive ssh root@SERVERIP "dd if=/dev/sda1 bs=1M status=progress | gzip -" | dd of=SERVERIP.sda1.dd.gz bs=1M
- The
bs=1M
is fairly random by me, worked well, didn’t care to optimize gzip
(with the default compression level) kind of maxed out the server CPU but still enabled me to almost max out my download bandwidth. Of course the ratio between remote CPU compression speed vs download bandwidth depends on your specific situation. You might want to usexz
orzstd
instead.
- The
- Don’t be stupid, do it twice and compare the checksums
If you do not need your server to be live during backup, you can skip the snapshotting and second server of course, just boot your server in rescue mode instead.
Build a new server from a backup
- Create a new server using the same or a similar configuration as the backed up one
- Boot said server in rescue mode
cat SERVERIP.sda1.dd.gz | ssh root@SERVERIP "gunzip -c | dd of=/dev/sda1 bs=1M status=progress conv=fsync"
- Reboot to leave rescue mode
If you want to restore your server because of a breakage, just boot it into rescue mode and do the same as above otherwise.
This won’t work as uuids in /etc/fstab will be wrong (if you used hetzner’s default config).
One solution is to configure the server to use labels as mountpoints in /etc/fstab
Weird, it had worked for me. Maybe it depends on the chosen distro?
It will work on the same server because it will have the same uuids, each new server instance gets new uuids regardless of distro (afaik).
I’ve got the error “grub_get_disk_size” after implementation of this guide, but I want to share how to fix it.
1) First go to /ISO images, find “Debian 12” and mount it.
2) After that boot from this image (in normal mode, not rescue)
3) Select “Rescue mode” in the Debian wizard, next “Run shell with /dev/sda1” and in the appeared command line run 2 commands:
# grub-install /dev/sda
# update-grub
i encountered “grub_file_filters_all” not found error, but your solution worked for me. (i only had an issue with the Debian 12 iso during Run shell with /dev/sda1 step, but it worked when i tried with kali iso)
Thank you for sharing this, Hannes!
Exactly what I was searching for.
I testet it. Created an image for my test-instance.
And recreated the same test-instance.
It worked like a charm, als long as the IP stays the same.
Spinning up a new server… Sometimes you get the same IP if you delete a server and spin up a new one. Sometimes you don’t.
But for keeping more snapshots as a “backup”, this works really great! Hetzner has snapshot limits.
Thanks again for sharing this post with us.
Great article.
By the way, using `pigz` instead of `gzip` gave me roughly 2x the performance while copying the backup. Can be installed on the rescue system via `apt install pigz`. Otherwise the whole process will be cpu-bound if you have a reasonably fast internet connection.
Thanks for this short tutorial.
I am still amazed Hetzner does not let us download the snapshot but lets us go the hard route to achieve this simpel thing….
One remark though:
I just blindly followed the steps without much thinking.
After downloading the 7GB of my ~40GB Hetzner disk, i had to
`cat vps.sda1.dd.gz | gunzip -c | dd of=test.img`
And could succesfully mount the image and retrieve data.
But I could not boot this disk in VirtualBox. (You have to convert it to VDI first anyway with VBoxManage convert)
The Trick is to clone full sda instead of sda1.
When i did this
ssh root@1.2.3.4 -i ~/.ssh/id_rsa “dd if=/dev/sda bs=32M status=progress | gzip -” | gunzip -c | dd of=sda_test2.img bs=32M
I got an IMG that i could convert with VBoxManage and it would boot without any problem….