Category: Backup

  • Comprehensive Guide to Backing Up Data to Hetzner Storage Boxes

    Comprehensive Guide to Backing Up Data to Hetzner Storage Boxes

    Hetzner Storage Boxes provide a cost-effective, scalable, and secure solution for online backups, supporting protocols like SFTP, SCP, rsync, and Samba/CIFS. This guide offers step-by-step instructions to back up data to Hetzner Storage Boxes, tailored for Linux, Windows, and macOS users, based on the latest information available as of August 15, 2025. It covers multiple methods, including rsync, Restic, and SimpleBackups, with a focus on automation, security, and efficiency.

    Prerequisites

    • Hetzner Storage Box: An active Storage Box account from Hetzner. Plans start at €3.20/month (~$3.50) for 1 TB.
    • Access Credentials: Username (e.g., uXXXXXX), password, and server address (e.g., uXXXXXX.your-storagebox.de).
    • System: Linux (e.g., Ubuntu 24.04), Windows (10/11), or macOS with terminal access.
    • Tools: Depending on the method, you’ll need rsync, Restic, autorestic, or a backup service like SimpleBackups.
    • Network: Stable internet connection; ports 22 (SSH) or 23 (SFTP/SCP) open.
    • Optional: SSH key for passwordless authentication.

    Step 1: Set Up Your Hetzner Storage Box

    1. Order a Storage Box:
    • Log in to your Hetzner account at robot.hetzner.com.
    • Select a Storage Box plan (e.g., BX11 for 1 TB at €3.20/month).
    • Wait for activation (typically ~3 minutes); you’ll receive a confirmation email with credentials (username, password, server).
    1. Enable SSH/SCP Access:
    • In the Hetzner Console, navigate to your Storage Box settings.
    • Enable SSH support and External reachability under “Change Settings.”
    • Reset the password if needed (visible only once after saving).
    1. Optional: Create a Sub-Account:
    • For multiple devices or users, create sub-accounts in the Hetzner Console.
    • Example: uXXXXXX-sub1 with access to a specific directory (e.g., subuser1/backups).
    • Note the sub-account’s endpoint (e.g., uXXXXXX-sub1.your-storagebox.de).
    1. Test SSH Connection:
    • On Linux/macOS:
      bash ssh -p 23 [email protected]
    • On Windows, use PowerShell or an SSH client like PuTTY.
    • Enter the password when prompted. If successful, you’ll see a command prompt.

    Step 2: Choose a Backup Method

    Below are three popular methods to back up data to Hetzner Storage Boxes, with detailed instructions for each.

    Method 1: Using rsync (Linux/macOS)

    rsync is a robust tool for syncing files to a remote server, ideal for incremental backups.

    1. Install rsync (if not pre-installed):
    • On Ubuntu/Debian:
      bash sudo apt-get update sudo apt-get install -y rsync
    • On macOS (via Homebrew):
      bash brew install rsync
    1. Set Up SSH Key for Passwordless Access (Optional but Recommended):
    • Generate an SSH key:
      bash ssh-keygen -t ed25519 -f ~/.ssh/hetzner_storagebox
    • Copy the public key to the Storage Box:
      bash cat ~/.ssh/hetzner_storagebox.pub | ssh -p 23 [email protected] install-ssh-key
    • Add to SSH config (~/.ssh/config):
      bash Host storagebox HostName uXXXXXX.your-storagebox.de User uXXXXXX Port 23 IdentityFile ~/.ssh/hetzner_storagebox
    1. Run an rsync Backup:
    • Back up a folder (e.g., /home/user/data) to a remote directory (e.g., backups):
      bash rsync -avh --progress -e 'ssh -p 23' --exclude 'temp' /home/user/data [email protected]:backups
    • Explanation:
      • -a: Archive mode (preserves permissions, timestamps).
      • -v: Verbose output.
      • -h: Human-readable sizes.
      • --progress: Show transfer progress.
      • --exclude 'temp': Skip temporary files.
      • Replace uXXXXXX and backups with your credentials and desired folder.
    1. Automate with an Alias:
    • Edit ~/.zshrc or ~/.bashrc:
      bash nano ~/.zshrc
    • Add:
      bash alias backup_hetzner="rsync -avh --progress -e 'ssh -p 23' --exclude 'temp' /home/user/data [email protected]:backups"
    • Reload shell:
      bash source ~/.zshrc
    • Run with:
      bash backup_hetzner
    1. Automate with Cron:
    • Edit crontab:
      bash crontab -e
    • Add for daily backups at 2 AM:
      bash 0 2 * * * rsync -avh --progress -e 'ssh -p 23' --exclude 'temp' /home/user/data [email protected]:backups
    1. Restore Data:
    • Reverse the rsync command:
      bash rsync -avh --progress -e 'ssh -p 23' [email protected]:backups /home/user/restored_data

    Source: Adapted from DeepakNess.

    Method 2: Using Restic (Linux/Windows/macOS)

    Restic is a secure, deduplicating backup tool, perfect for encrypted backups to Hetzner.

    1. Install Restic:
    • Linux (Ubuntu):
      bash sudo apt-get install restic
    • macOS (Homebrew):
      bash brew install restic
    • Windows: Download from Restic GitHub, extract to C:\restic, and add to PATH.
    1. Set Up SSH Key (as in rsync method).
    2. Configure SSH for Restic:
    • Edit ~/.ssh/config:
      bash Host storagebox HostName uXXXXXX.your-storagebox.de User uXXXXXX Port 23 IdentityFile ~/.ssh/hetzner_storagebox
    1. Initialize Restic Repository:
    • Run:
      bash restic -r sftp:storagebox:/restic init
    • Enter a repository password and save it securely.
    1. Back Up Data:
    • Back up a directory (e.g., /home/user/data):
      bash restic -r sftp:storagebox:/restic backup /home/user/data
    • Exclude files:
      bash restic -r sftp:storagebox:/restic backup /home/user/data --exclude "*.tmp"
    1. Automate with autorestic (Optional):
    • Install autorestic:
      bash wget -qO - https://raw.githubusercontent.com/cupcakearmy/autorestic/master/install.sh | bash
    • Create .autorestic.yml:
      yaml version: 2 locations: home: from: /home/user/data to: storagebox backends: storagebox: type: sftp path: storagebox:/restic key: your-repository-password
    • Run backup:
      bash autorestic -av backup
    1. Check Snapshots:
    • View backups:
      bash restic -r sftp:storagebox:/restic snapshots
    1. Restore Data:
    • Restore to a directory:
      bash restic -r sftp:storagebox:/restic restore latest --target /home/user/restored

    Source: Adapted from blog.9wd.eu.

    Method 3: Using SimpleBackups (Cloud-Based)

    SimpleBackups is a managed backup service that simplifies automation to Hetzner Storage Boxes.

    1. Set Up SimpleBackups:
    1. Configure Hetzner Storage Box:
    • Select SFTP as the provider.
    • Enter:
      • Host: uXXXXXX.your-storagebox.de (or sub-account endpoint, e.g., uXXXXXX-sub1.your-storagebox.de).
      • User: uXXXXXX (or sub-account).
      • Password: From Hetzner Console.
      • Path: Relative path (e.g., backups, not subuser1/backups).
    • Validate the connection and save with a friendly name.
    1. Create a Backup Job:
    • Go to Backup > Create Backup.
    • Select files, databases, or servers to back up.
    • Choose the Hetzner Storage Box as the destination.
    • Set a schedule (e.g., daily, weekly).
    1. Monitor and Restore:
    • Use SimpleBackups’ dashboard to monitor backups and initiate restores.

    Source: Adapted from docs.simplebackups.com.

    Step 3: Additional Configuration

    • Snapshots: Hetzner supports 10–40 snapshots (plan-dependent). Create manual snapshots or automate them in the Hetzner Console for data recovery.
    • Sub-Accounts for Multiple Devices: Use sub-accounts to segregate backups (e.g., uXXXXXX-sub1 for a laptop, sub2 for a server).
    • Connection Limits: Hetzner allows 10 concurrent connections per sub-account. For Restic, use --limit-upload 1000 to throttle bandwidth (in KB/s).
    • Encryption: Restic provides built-in encryption; for rsync, consider encrypting sensitive data locally before transfer.

    Step 4: Troubleshooting

    • Connection Refused: Ensure port 23 is open (telnet uXXXXXX.your-storagebox.de 23) and SSH is enabled in Hetzner Console.
    • Permission Denied: Verify username/password or SSH key setup. Reset password if needed.
    • Slow Transfers: Check network speed or throttle with rsync (--bwlimit=1000) or Restic (--limit-upload 1000).
    • Path Errors: For sub-accounts, use the correct endpoint and relative path (e.g., backups not subuser1/backups).
    • Connection Limits Exceeded: Reduce concurrent transfers (e.g., Restic: --limit-upload 500).

    Security Considerations

    • SSH Keys: Use SSH keys for passwordless, secure access.
    • Encryption: Restic encrypts data; for rsync, encrypt sensitive files locally.
    • Access Control: Restrict sub-account directories to specific users.
    • Monitoring: Regularly check snapshots and backup integrity.

    Conclusion

    Backing up to Hetzner Storage Boxes is straightforward with tools like rsync (for simple syncing), Restic (for encrypted, deduplicated backups), or SimpleBackups (for managed automation). Each method offers flexibility depending on your needs—rsync for Linux/macOS users, Restic for cross-platform security, and SimpleBackups for ease of use. With prices starting at €3.20/month and robust protocols, Hetzner is ideal for cost-effective backups. Verify setup details at hetzner.com and test with a small dataset first.

    Sources: Adapted from Hetzner Docs, DeepakNess, blog.9wd.eu, and docs.simplebackups.com.