Last active
July 30, 2024 11:46
-
-
Save mlazzarotto/8fc5507b71d91c453ce1a32d022e1b76 to your computer and use it in GitHub Desktop.
List all Proxmox snapshots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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