hcloud-backup

GitHub Release

Ansible Role: kimdre.hcloud-backup

Ansible role to create and rotate backups and snapshots of servers in Hetzner Cloud.

Requirements

  • Ansible 2.15 or later

Role Variables

api_token

Hetzner Cloud API token.

Example

api_token: "your-hcloud-token"

Can also be set as an environment variable HCLOUD_TOKEN

Default Variables

See hcloud-backup/defaults/main.yml for all available variables.

backup_type

Type of backup to create.

Possible formats:

  • snapshot is generally cheaper with smaller servers and disk usage and there is no limit on the number of snapshots that can be created.
  • backup needs to be enabled first for the server and only 7 backups can be created per server before they get rotated.

Default value

backup_type: snapshot

backup_description

Description of the snapshot/backup.

Default value

backup_description: "{{ inventory_hostname }} {{ now(fmt='%Y-%m-%d %H:%M:%S') }}"

backup_labels

List of labels of the snapshot/backup.

Possible formats:

  • key: "value"
  • key: "" for labels without a value.

Default value

backup_labels:
    created_by: "ansible.hcloud-backup"
    created_at: "{{ now(fmt='%Y-%m-%d_%H-%M-%S') }}"
    host: "{{ inventory_hostname }}"
    rotation: "true"

label_selector

List of labels to identify snapshots for rotation, should overlap with backup_labels.

Only used when backup_type is set to snapshot.

Possible formats:

  • key: "value"
  • key: "" for labels without a value.

Default value

label_selector:
    created_by: ansible.hcloud-backup
    host: "{{ inventory_hostname }}"
    rotation: "true"

rotate_snapshots

Rotate snapshots, if set to true, the oldest found snapshot(s) will be deleted depending on the keep_snapshots variable and the number of existing snapshots.

Only used when backup_type is set to snapshot.

Default value

rotate_snapshots: true

keep_snapshots

Number of snapshots to keep, older snapshots will be deleted.

Only used when backup_type is set to snapshot and rotate_snapshots is set to true.

Default value

keep_snapshots: 5

backup_check_retries

Number of retries for the backup creation check.

Default value

backup_check_retries: 40

backup_check_delay

Delay in seconds between retries for the backup creation check.

Default value

backup_check_delay: 15

delegation

Host to run the role tasks from

Default value

delegation: "{{ inventory_hostname }}"

Example Playbook

- name: "Create snapshot of host"
  hosts: '{{ target | default("all") }}'
  roles:
    - role: kimdre.hcloud-backup
      vars:
        api_token: "your-hcloud-api-token"
        backup_type: "snapshot"
        keep_snapshots: 7

License

Apache-2.0

Author

About

Ansible role for Hetzner Cloud to create and rotate backups and snapshots of your servers

Install
ansible-galaxy install kimdre/ansible.hcloud-backup
GitHub repository
License
apache-2.0
Downloads
552
Owner
DevOps engineer and linux admin, also a mountainbike enthusiast! 🚵‍♂️ Founder of @Maki-IT.