Virtualization, Servers and Storage : How-to list all Virtual Machines with Snapshots

Managing virtual machine (VM) snapshots is a critical part of maintaining and troubleshooting VMs in the University of Toronto's ITS Private Cloud. Snapshots allow you to capture the state of a VM at a specific point in time, which is invaluable for upgrades, testing, and recovery. This guide will show you how to list all VMs with snapshots, using the vss-cli tool, and how to retrieve detailed snapshot information.

Prerequisites

  • vss-cli installed: Ensure you have the vss-cli or access to the web interface installed or ssh access to vsscli-demo.eis.utoronto.ca, and configured with your credentials.

  • Access permissions: You must have permission to view VMs and snapshots in the target folder.

Quick Command: List VMs with Snapshots

To list all VMs in the Systems folder that have at least one snapshot, use:

vss-cli compute vm ls -f has_snapshot=1 -f folder.path=Systems
  • -f has_snapshot=1: Filters for VMs that have snapshots.

  • -f folder.path=Systems: Restricts results to VMs in the "Systems" folder.

You can add --columns to customize the output, e.g.:

vss-cli --columns moref,name,folder.path compute vm ls -f has_snapshot=1 -f folder.path=Systems

Script: List VMs and Their Snapshots (with Details)

For a more detailed report—including snapshot IDs and metadata—use the following script:

#!/bin/bash
set -euo pipefail

# List VMs with snapshot in the Systems folder
vss-cli --no-headers --columns moref --table-format plain \
    compute vm ls -f has_snapshot=1 -f folder.path=Systems -s power_state |
while read -r vm; do
    # List snapshot IDs for each VM
    vss-cli --no-headers --columns id --table-format plain \
        compute vm get "$vm" snapshot |
    while read -r snap_id; do
        # Validate that snap_id is a number (integer)
        if [[ "$snap_id" =~ ^[0-9]+$ ]]; then
            echo "VM: $vm | Snapshot ID: $snap_id"
            vss-cli --columns create_time,age,size_gb,name \
                compute vm get "$vm" snapshot "$snap_id"
        else
            echo "Warning: Snapshot ID '$snap_id' for VM '$vm' is not a valid number. Skipping." >&2
        fi
    done
done

What This Script Does

  • Step 1: Lists all VMs in the "Systems" folder with snapshots.

  • Step 2: For each VM, lists all snapshot IDs.

  • Step 3: For each snapshot, prints details: creation time, age, size, and name.

  • Step 4: Skips any invalid snapshot IDs (should not occur, but is a safety check).

Understanding the Output

  • VM: The Managed Object Reference (moref) of the VM.

  • Snapshot ID: Unique identifier for each snapshot.

  • Details: Creation time, age (how long the snapshot has existed), size in GB, and the snapshot name.

Best Practices & Notes

  • Snapshot Management: Snapshots are not backups; they are delta files tracking changes. Too many or old snapshots can degrade performance and consume excessive storage.

  • Snapshot Lifecycle: Snapshots have a start and end date. You can extend their lifetime (up to 72 hours, three times), revert to them, or delete them as needed.

  • Consolidation: After deleting snapshots, disk consolidation may be required to reclaim space and improve performance.

  • Permissions: If you see errors or missing VMs, check your folder permissions.

Troubleshooting

  • No Results? Double-check the folder path and your permissions.

  • Invalid Snapshot IDs? This is rare; the script will warn you if it encounters any.

  • Performance: For large environments, consider adding pagination or limiting results with -c <count>.

Further Reading

Summary Table

Command/Script

Purpose

vss-cli compute vm ls -f has_snapshot=1 -f folder.path=Systems

List VMs with snapshots in "Systems" folder

Script above

List VMs and detailed snapshot info

vss-cli compute vm get <vm-id> snapshot

List snapshots for a specific VM

vss-cli compute vm get <vm-id> snapshot <snap-id>

Get details for a specific snapshot

Always clean up old snapshots to maintain VM performance and storage efficiency!

If you need help with advanced filtering, custom columns, or troubleshooting, reach out to ITS Private Cloud support via https://utor.cloud/help or consult the vss-cli documentation.