Ansible role to create and rotate backups and snapshots of servers in Hetzner Cloud.
- Ansible 2.15 or later
Hetzner Cloud API token.
Example
api_token: "your-hcloud-token"Can also be set as an environment variable HCLOUD_TOKEN
See hcloud-backup/defaults/main.yml for all available variables.
Type of backup to create.
snapshotis generally cheaper with smaller servers and disk usage and there is no limit on the number of snapshots that can be created.backupneeds to be enabled first for the server and only 7 backups can be created per server before they get rotated.
backup_type: snapshotDescription of the snapshot/backup.
backup_description: "{{ inventory_hostname }} {{ now(fmt='%Y-%m-%d %H:%M:%S') }}"List of labels of the snapshot/backup.
key: "value"key: ""for labels without a value.
backup_labels:
created_by: "ansible.hcloud-backup"
created_at: "{{ now(fmt='%Y-%m-%d_%H-%M-%S') }}"
host: "{{ inventory_hostname }}"
rotation: "true"List of labels to identify snapshots for rotation, should overlap with backup_labels.
Only used when backup_type is set to snapshot.
key: "value"key: ""for labels without a value.
label_selector:
created_by: ansible.hcloud-backup
host: "{{ inventory_hostname }}"
rotation: "true"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.
rotate_snapshots: trueNumber 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.
keep_snapshots: 5Number of retries for the backup creation check.
backup_check_retries: 40Delay in seconds between retries for the backup creation check.
backup_check_delay: 15Host to run the role tasks from
delegation: "{{ inventory_hostname }}"- 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: 7Apache-2.0