Skip to content

feature: add support for VM backup and retention #1815

Open
@149segolte

Description

@149segolte

Is your feature request related to a problem? Please describe.

As a followup from #406. Whenever deploying any non-ephemeral VMs (like storage providers, nfs server etc.) they require a backup policy to ensure the VM's data is properly backed up to something like Proxmox Backup Server.

Describe the solution you'd like

For defining backup policy there two ways that seem viable:

  • As Proxmox backup supports multiple VMs as part of a single job, we can have a resource "proxmox_virtual_environment_backup_job" that will have the properties defined on it, with a targets list containing VM ids. These ids can be taken after VM resources are deployed, making so that terraform will create the backup job after all the target VMs are created.
    Example:
resource "proxmox_virtual_environment_backup_job" "backup" {
  targets = [
    proxmox_virtual_environment_vm.data_provider1.vm_id
    proxmox_virtual_environment_vm.data_server2.vm_id
  ]

  preserve_data_on_delete = true  # Special key to denote whether to remove backups with the job on destroy, or to only remove the job

  # properties like,
  datastore_id = "local"
  compression = "zstd"
  schedule = "*/2:00"
}
  • Another way could be to define a backup block in each VM config that will create a backup job with only that VM as the target. This method will allow more granularity with one job per VM and duplication of similar blocks in each VM will not a problem as we can just create a locals block and dynamically create the backup block.
    Example:
resource "proxmox_virtual_environment_backup_job" "backup" {
  name = "data_provider1"

  backup {
    datastore_id = "local"
    compression = "lzo"
    schedule = "*/1:00"
  }

  # rest of the properties
}

Restore functionality

Restoring is a little trickier to define. Particularly if the VM was removed and is being redeployed at a later point with the intention of restoring from a backup. This will require the VM's id to be known outside of terraform_state. Therefore it will not work with random_ids on the provider. Other than that, we can define the restore for VMs as,

resource "proxmox_virtual_environment_backup_job" "backup" {
  name = "data_server2"
  vm_id = "1234"

  restore {
    enabled = true
    datastore_id = "local"
    override = {
      name = "new_data_server2"
    }
  }

  # rest of the properties
}

This will work as a storage pool keeps the backup around even if both the VM and the backup job that created it are gone. But to associate a previous backup with the current deployment, the VM ids should match. We can handle it such that, on deployment, if a VM has a restore block we first check the given datastore for a backup with the VM id, if found we restore instead of deploying, otherwise we simply deploy.

Additional context

Proxmox backup job options:
Image

Proxmox restore VM options:
Image

Metadata

Metadata

Assignees

No one assigned

    Projects

    • Status

      ☑️ Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions