community.general.proxmox_backup module – Start a VM backup in Proxmox VE cluster

Note

This module is part of the community.general collection (version 10.1.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.general.proxmox_backup.

New in community.general 10.1.0

Synopsis

  • Allows you to create backups of KVM and LXC guests in Proxmox VE cluster.

  • Offers the GUI functionality of creating a single backup as well as using the run-now functionality from the cluster backup schedule.

  • The mininum required privileges to use this module are VM.Backup and Datastore.AllocateSpace for the respective VMs and storage.

  • Most options are optional and if unspecified will be chosen by the Cluster and its default values.

  • Note that this module is not idempotent. It always starts a new backup (when not in check mode).

Requirements

The below requirements are needed on the host that executes this module.

  • proxmoxer

  • requests

Parameters

Parameter

Comments

api_host

string / required

Specify the target host of the Proxmox VE cluster.

api_password

string

Specify the password to authenticate with.

You can use PROXMOX_PASSWORD environment variable.

api_port

integer

added in community.general 9.1.0

Specify the target port of the Proxmox VE cluster.

Uses the PROXMOX_PORT environment variable if not specified.

api_token_id

string

added in community.general 1.3.0

Specify the token ID.

Requires proxmoxer>=1.1.0 to work.

api_token_secret

string

added in community.general 1.3.0

Specify the token secret.

Requires proxmoxer>=1.1.0 to work.

api_user

string / required

Specify the user to authenticate with.

backup_mode

string

The mode how Proxmox performs backups. The default is, to create a runtime snapshot including memory.

Check https://pve.proxmox.com/pve-docs/chapter-vzdump.html#_backup_modes for an explanation of the differences.

Choices:

  • "snapshot" ← (default)

  • "suspend"

  • "stop"

bandwidth

integer

Limit the I/O bandwidth (in KiB/s) to write backup. 0 is unlimited.

change_detection_mode

string

Set the change detection mode (available from Proxmox VE 8.3).

Is only used when backing up containers, Proxmox silently ignores this option when applied to kvm guests.

Choices:

  • "legacy"

  • "data"

  • "metadata"

compress

string

Enable additional compression of the backup archive.

0 will use the Proxmox recommended value, depending on your storage target.

Choices:

  • "0"

  • "1"

  • "gzip"

  • "lzo"

  • "zstd"

compression_threads

integer

The number of threads zstd will use to compress the backup.

0 uses 50% of the available cores, anything larger than 0 will use exactly as many threads.

Is ignored if you specify compress=gzip or compress=lzo.

description

string

Specify the description of the backup.

Needs to be a single line, newline and backslash need to be escaped as \n and \\ respectively.

If you need variable interpolation, you can set the content as usual through ansible jinja templating and/or let Proxmox substitute templates.

Proxmox currently supports {{cluster}}, {{guestname}}, {{node}}, and {{vmid}} as templating variables. Since this is also a jinja delimiter, you need to set these values as raw jinja.

Default: "{{guestname}}"

fleecing

string

Enable backup fleecing. Works only for virtual machines and their disks.

Must be entered as a string, containing key-value pairs in a list.

mode

string / required

Specifices the mode to select backup targets.

Choices:

  • "include"

  • "all"

  • "pool"

node

string

Only execute the backup job for the given node.

This option is usually used if mode=all.

If you specify a node ID and your vmids or pool do not reside there, they will not be backed up!

notification_mode

string

Determine which notification system to use.

Choices:

  • "auto" ← (default)

  • "legacy-sendmail"

  • "notification-system"

performance_tweaks

string

Enable other performance-related settings.

Must be entered as a string, containing comma separated key-value pairs.

For example: max-workers=2,pbs-entries-max=2.

pool

string

Specify a pool name to limit backups to guests to the given pool.

Required, when mode=pool.

Also required, when your user only has VM.Backup permission for this single pool.

protected

boolean

Marks backups as protected.

“Might fail, when the PBS backend has verify enabled due to this bug: https://bugzilla.proxmox.com/show_bug.cgi?id=4289

Choices:

  • false

  • true

retention

string

Use custom retention options instead of those from the default cluster configuration (which is usually "keep-all").

Always requires Datastore.Allocate permission at the storage endpoint.

Specifying a retention time other than keep-all=1 might trigger pruning on the datastore, if an existing backup should be deleted target due to your specified timeframe.

Deleting requires Datastore.Modify or Datastore.Prune permissions on the backup storage.

storage

string / required

Store the backup archive on this storage.

validate_certs

boolean

If false, SSL certificates will not be validated.

This should only be used on personally controlled sites using self-signed certificates.

Choices:

  • false ← (default)

  • true

vmids

list / elements=integer

The instance ids to be backed up.

Only valid, if mode=include.

wait

boolean

Wait for the backup to be finished.

Fails, if job does not succeed successfully within the given timeout.

Choices:

  • false ← (default)

  • true

wait_timeout

integer

Seconds to wait for the backup to be finished.

Will only be evaluated, if wait=true.

Default: 10

Attributes

Attribute

Support

Description

action_group

Action group: community.general.proxmox

Use group/community.general.proxmox in module_defaults to set defaults for this module.

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: none

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

Examples

- name: Backup all vms in the Proxmox cluster to storage mypbs
  community.general.proxmox_backup:
    api_user: root@pam
    api_password: secret
    api_host: node1
    storage: mypbs
    mode: all

- name: Backup VMID 100 by stopping it and set an individual retention
  community.general.proxmox_backup:
    api_user: root@pam
    api_password: secret
    api_host: node1
    backup-mode: stop
    mode: include
    retention: keep-daily=5, keep-last=14, keep-monthly=4, keep-weekly=4, keep-yearly=0
    storage: mypbs
    vmid: [100]

- name: Backup all vms on node node2 to storage mypbs and wait for the task to finish
  community.general.proxmox_backup:
    api_user: test@pve
    api_password: 1q2w3e
    api_host: node2
    storage: mypbs
    mode: all
    node: node2
    wait: true
    wait_timeout: 30

- name: Use all the options
  community.general.proxmox_backup:
    api_user: root@pam
    api_password: secret
    api_host: node1
    bandwidth: 1000
    backup_mode: suspend
    compress: zstd
    compression_threads: 0
    description: A single backup for {% raw %}{{ guestname }}{% endraw %}
    mode: include
    notification_mode: notification-system
    protected: true
    retention: keep-monthly=1, keep-weekly=1
    storage: mypbs
    vmids:
      - 100
      - 101

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

backups

list / elements=dictionary

List of nodes and their task IDs.

Returned: on success

node

string

Node ID.

Returned: on success

status

string

Last known task status. Will be unknown, if wait=false.

Returned: on success

Can only return:

  • "unknown"

  • "success"

  • "failed"

upid

string

Proxmox cluster UPID, which is needed to lookup task info. Returns OK, when a cluster node did not create a task after being called, e.g. due to no matching targets.

Returned: on success

Authors

  • Raphael Grieger (@IamLunchbox)