Backing up Hetzner snapshots locally

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 and gzip 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 use xz or zstd instead.
  • 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.

5 thoughts on “Backing up Hetzner snapshots locally

  1. v3d

    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

    Reply
      1. v3d

        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).

        Reply
  2. Andrey

    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

    Reply
    1. lodos2005

      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)

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.