Skip to content

Proxmox VE snapshots from PowerShell

Get-PveGuestSnapshot, New-PveGuestSnapshot, Undo-PveGuestSnapshot and Remove-PveGuestSnapshot take the guests with the selection of Get-PveGuest, like the power functions: for each guest they find its node and type and call the qemu or lxc snapshot endpoint.

# list
(Get-PveGuestSnapshot -VmIdOrName web01).Response.data |
Format-Table name, description, @{ n = 'taken'; e = { if ($_.snaptime) { ConvertFrom-PveUnixTime $_.snaptime } } }
# take
New-PveGuestSnapshot -VmIdOrName web01 -Snapname before-update -Description 'Before the monthly update'
# roll back
Undo-PveGuestSnapshot -VmIdOrName web01 -Snapname before-update
# delete
Remove-PveGuestSnapshot -VmIdOrName web01 -Snapname before-update

The list includes an entry named current, the running state of the guest, without snaptime.

They return one PveResponse per guest. Taking, rolling back and deleting are tasks: the UPID is in .Response.data, and the next step of the script should wait for it. -Description is optional; when you leave it out the snapshot has none.

The former names Get-PveVmSnapshot, New-PveVmSnapshot, … still work as aliases.

For a running VM, -Vmstate also saves the memory, so a rollback resumes the VM where it was instead of booting it:

New-PveGuestSnapshot -VmIdOrName web01 -Snapname before-update -Vmstate

Here -Vmstate is a switch. Containers have no memory state: the switch is ignored for them.

One call takes a snapshot of every guest of the selection; wait for each task and check how it ended:

$name = "pre$(Get-Date -Format yyyyMMdd)"
New-PveGuestSnapshot -VmIdOrName '@tag-update-tonight' -Snapname $name -Description 'Before the monthly update' |
ForEach-Object {
if (-not $_.IsSuccessStatusCode) { Write-Warning "$($_.RequestResource): $($_.ReasonPhrase)"; return }
if ($_ | Wait-PveTaskIsFinish -Timeout 300000) {
"$($_.RequestResource): $(Get-PveTaskExitStatus -Upid $_.Response.data)"
}
}

A snapshot name must start with a letter and may contain letters, digits, - and _: the date goes after a prefix, as above.

On ZFS storage a guest can roll back only to its most recent snapshot. To go back further, delete the newer snapshots first; otherwise the task fails with can't rollback, '<snapshot>' is not most recent snapshot on '<disk>'.