Skip to content

Instantly share code, notes, and snippets.

@mlazzarotto
Last active July 30, 2024 11:46
Show Gist options
  • Save mlazzarotto/8fc5507b71d91c453ce1a32d022e1b76 to your computer and use it in GitHub Desktop.
Save mlazzarotto/8fc5507b71d91c453ce1a32d022e1b76 to your computer and use it in GitHub Desktop.
List all Proxmox snapshots
#!/usr/bin/env bash
echo "Printing VM snapshots..."
nodes=$(pvesh get /cluster/resources --type vm --output-format json |jq -r '.[] | [.vmid, .name, .node, .type] | @json')
echo "Processing data ..."
for i in $nodes; do
vmtype=$(jq -r '.[3]' <<< "$i");
if [[ "$vmtype" == "qemu" ]]; then
#printf "\n i= $i" # -- shows all iterations for troubleshooting
vmid=$(jq -r '.[0]' <<< "$i");
vmname=$(jq -r '.[1]' <<< "$i");
node=$(jq -r '.[2]' <<< "$i");
snapshots=$(pvesh get "/nodes/$node/qemu/$vmid/snapshot" --output-format=json)
snapdates=""
snapdates=$(echo "$snapshots" | jq -r '[.[] | select(.snaptime) | (.snaptime | tonumber | todate[:10])] | @csv ');
snapname=""
snapname=$(echo "$snapshots" | jq -r '.[0].name');
if [[ $snapdates ]]; then
printf "\n $node \t $vmid \t $vmname \t date: $snapdates \t name: $snapname"
fi
elif [[ "$vmtype" == "lxc" ]]; then
#printf "\n i= $i" # -- shows all iterations for troubleshooting
vmid=$(jq -r '.[0]' <<< "$i");
vmname=$(jq -r '.[1]' <<< "$i");
node=$(jq -r '.[2]' <<< "$i");
snapshots=$(pvesh get "/nodes/$node/lxc/$vmid/snapshot" --output-format=json)
snapdates=""
snapdates=$(echo "$snapshots" | jq -r '[.[] | select(.snaptime) | (.snaptime | tonumber | todate[:10])] | @csv ');
snapname=""
snapname=$(echo "$snapshots" | jq -r '.[0].name');
if [[ $snapdates ]]; then
printf "\n $node \t $vmid \t $vmname \t date: $snapdates \t name: $snapname"
fi
fi
done;
printf "\n processing complete. \n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment