kimdre.hcloud-backup
Ansible Role: kimdre.hcloud-backup
This is an Ansible role designed to create and manage backups and snapshots of servers in Hetzner Cloud.
Requirements
- You need Ansible version 2.15 or newer.
Role Variables
api_token
This is your Hetzner Cloud API token.
Example
api_token: "your-hcloud-token"
You can also set it as an environment variable named HCLOUD_TOKEN
.
Default Variables
You can find all available variables in hcloud-backup/defaults/main.yml.
backup_type
This indicates the type of backup you want to create.
Options:
snapshot
: Typically cheaper for smaller servers and does not have a limit on how many can be created.backup
: Must be enabled for the server first, and you can only have 7 backups before they start getting rotated.
Default value
backup_type: snapshot
backup_description
This is a description for the snapshot or backup.
Default value
backup_description: "{{ inventory_hostname }} {{ now(fmt='%Y-%m-%d %H:%M:%S') }}"
backup_labels
These are labels you can assign to the snapshot or backup.
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
Labels used to find snapshots for rotation. They should match the backup_labels
.
Only relevant if backup_type
is set to snapshot
.
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
If set to true
, the oldest snapshots will be deleted based on the keep_snapshots
setting.
Used only when backup_type
is set to snapshot
.
Default value
rotate_snapshots: true
keep_snapshots
This defines how many snapshots you want to keep. Older ones will be deleted.
Relevant only if backup_type
is snapshot
and rotate_snapshots
is true
.
Default value
keep_snapshots: 5
backup_check_retries
Number of attempts to check if the backup creation was successful.
Default value
backup_check_retries: 40
backup_check_delay
How long to wait in seconds between retries for checking backup creation.
Default value
backup_check_delay: 15
delegation
This is the host where the role tasks will run from.
Default value
delegation: "{{ inventory_hostname }}"
Example Playbook
Here's a simple example of how to use the role:
- 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
This role is licensed under Apache-2.0.
Author
Ansible role for Hetzner Cloud to create and rotate backups and snapshots of your servers
ansible-galaxy install kimdre.hcloud-backup