VMware Cloud Community
tivs
Enthusiast
Enthusiast
Jump to solution

How to find age of a snapshot and child snapshot count for a VM.

Hi All,

    How to find age of a snapshot and Child Snapshot count for a VM.

1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

This snippet of code should help.. Assuming you have the following inputs:

vm (VC:VirtualMachine)

snapshot (VC:VirtualMachineSnapshot)

System.log("====== Snapshot details for VM: "+snapshot.config.name+" ======");

var snapshotTrees = vm.snapshot.rootSnapshotList;

System.log("Snapshot Tree Count: "+snapshotTrees.length);

for each (snapshotTree in snapshotTrees){

    showSnapshotInfo(snapshotTree, snapshot);

}

function showSnapshotInfo(snapshotTree, selectedSnapshot){

    if(selectedSnapshot == snapshotTree.snapshot){

        System.log("====================");

        System.log("Name: "+snapshotTree.name);

        System.log("Id: "+snapshotTree.id);

        System.log("Description: "+snapshotTree.description);

        System.log("createTime: "+snapshotTree.createTime);

        System.log("quiesced: "+snapshotTree.quiesced);

        System.log("replaySupported: "+snapshotTree.replaySupported);

        System.log("backupManifest: "+snapshotTree.backupManifest);

        System.log("snapshot id: "+snapshotTree.snapshot.id);

        System.log("state: "+snapshotTree.state.value);

        var childSnapshotList = snapshotTree.childSnapshotList;

        if(childSnapshotList != null){

            System.log("childSnapshotList length: "+snapshotTree.childSnapshotList.length);

        }

        System.log("");

    }

    if(snapshotTree.childSnapshotList != null){

        System.log("Children found: "+snapshotTree.childSnapshotList.length);

        for each (childSnapshotTree in snapshotTree.childSnapshotList){

            showSnapshotInfo(childSnapshotTree, selectedSnapshot);

        }

    }

}

When I pass one of my VMs, here is an example of the output I receive:

[2014-06-12 15:19:21.493] [I] Snapshot Tree Count: 1

[2014-06-12 15:19:21.493] [I] ====================

[2014-06-12 15:19:21.494] [I] Name: before upgrade to 5.0.1

[2014-06-12 15:19:21.494] [I] Id: 31

[2014-06-12 15:19:21.494] [I] Description:

[2014-06-12 15:19:21.495] [I] createTime: Mon Mar 19 2012 13:48:57 GMT-0400 (EDT)

[2014-06-12 15:19:21.495] [I] quiesced: false

[2014-06-12 15:19:21.495] [I] replaySupported: null

[2014-06-12 15:19:21.495] [I] backupManifest: null

[2014-06-12 15:19:21.496] [I] snapshot id: snapshot-83

[2014-06-12 15:19:21.496] [I] state: poweredOff

[2014-06-12 15:19:21.496] [I] childSnapshotList length: 1

[2014-06-12 15:19:21.496] [I]

[2014-06-12 15:19:21.497] [I] ====================

[2014-06-12 15:19:21.497] [I] Name: Before 5.1 upgrade

[2014-06-12 15:19:21.497] [I] Id: 36

[2014-06-12 15:19:21.497] [I] Description:

[2014-06-12 15:19:21.498] [I] createTime: Fri Sep 21 2012 21:59:58 GMT-0400 (EDT)

[2014-06-12 15:19:21.498] [I] quiesced: false

[2014-06-12 15:19:21.498] [I] replaySupported: null

[2014-06-12 15:19:21.498] [I] backupManifest: null

[2014-06-12 15:19:21.499] [I] snapshot id: snapshot-84

[2014-06-12 15:19:21.499] [I] state: poweredOff

[2014-06-12 15:19:21.499] [I] childSnapshotList length: 1

[2014-06-12 15:19:21.499] [I]

[2014-06-12 15:19:21.500] [I] ====================

[2014-06-12 15:19:21.500] [I] Name: Before Named Instance

[2014-06-12 15:19:21.500] [I] Id: 37

[2014-06-12 15:19:21.501] [I] Description:

[2014-06-12 15:19:21.501] [I] createTime: Mon Nov 11 2013 13:40:46 GMT-0500 (EST)

[2014-06-12 15:19:21.501] [I] quiesced: false

[2014-06-12 15:19:21.501] [I] replaySupported: null

[2014-06-12 15:19:21.502] [I] backupManifest: null

[2014-06-12 15:19:21.502] [I] snapshot id: snapshot-236

[2014-06-12 15:19:21.502] [I] state: poweredOff

[2014-06-12 15:19:21.502] [I]

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

1 Reply
Burke-
VMware Employee
VMware Employee
Jump to solution

This snippet of code should help.. Assuming you have the following inputs:

vm (VC:VirtualMachine)

snapshot (VC:VirtualMachineSnapshot)

System.log("====== Snapshot details for VM: "+snapshot.config.name+" ======");

var snapshotTrees = vm.snapshot.rootSnapshotList;

System.log("Snapshot Tree Count: "+snapshotTrees.length);

for each (snapshotTree in snapshotTrees){

    showSnapshotInfo(snapshotTree, snapshot);

}

function showSnapshotInfo(snapshotTree, selectedSnapshot){

    if(selectedSnapshot == snapshotTree.snapshot){

        System.log("====================");

        System.log("Name: "+snapshotTree.name);

        System.log("Id: "+snapshotTree.id);

        System.log("Description: "+snapshotTree.description);

        System.log("createTime: "+snapshotTree.createTime);

        System.log("quiesced: "+snapshotTree.quiesced);

        System.log("replaySupported: "+snapshotTree.replaySupported);

        System.log("backupManifest: "+snapshotTree.backupManifest);

        System.log("snapshot id: "+snapshotTree.snapshot.id);

        System.log("state: "+snapshotTree.state.value);

        var childSnapshotList = snapshotTree.childSnapshotList;

        if(childSnapshotList != null){

            System.log("childSnapshotList length: "+snapshotTree.childSnapshotList.length);

        }

        System.log("");

    }

    if(snapshotTree.childSnapshotList != null){

        System.log("Children found: "+snapshotTree.childSnapshotList.length);

        for each (childSnapshotTree in snapshotTree.childSnapshotList){

            showSnapshotInfo(childSnapshotTree, selectedSnapshot);

        }

    }

}

When I pass one of my VMs, here is an example of the output I receive:

[2014-06-12 15:19:21.493] [I] Snapshot Tree Count: 1

[2014-06-12 15:19:21.493] [I] ====================

[2014-06-12 15:19:21.494] [I] Name: before upgrade to 5.0.1

[2014-06-12 15:19:21.494] [I] Id: 31

[2014-06-12 15:19:21.494] [I] Description:

[2014-06-12 15:19:21.495] [I] createTime: Mon Mar 19 2012 13:48:57 GMT-0400 (EDT)

[2014-06-12 15:19:21.495] [I] quiesced: false

[2014-06-12 15:19:21.495] [I] replaySupported: null

[2014-06-12 15:19:21.495] [I] backupManifest: null

[2014-06-12 15:19:21.496] [I] snapshot id: snapshot-83

[2014-06-12 15:19:21.496] [I] state: poweredOff

[2014-06-12 15:19:21.496] [I] childSnapshotList length: 1

[2014-06-12 15:19:21.496] [I]

[2014-06-12 15:19:21.497] [I] ====================

[2014-06-12 15:19:21.497] [I] Name: Before 5.1 upgrade

[2014-06-12 15:19:21.497] [I] Id: 36

[2014-06-12 15:19:21.497] [I] Description:

[2014-06-12 15:19:21.498] [I] createTime: Fri Sep 21 2012 21:59:58 GMT-0400 (EDT)

[2014-06-12 15:19:21.498] [I] quiesced: false

[2014-06-12 15:19:21.498] [I] replaySupported: null

[2014-06-12 15:19:21.498] [I] backupManifest: null

[2014-06-12 15:19:21.499] [I] snapshot id: snapshot-84

[2014-06-12 15:19:21.499] [I] state: poweredOff

[2014-06-12 15:19:21.499] [I] childSnapshotList length: 1

[2014-06-12 15:19:21.499] [I]

[2014-06-12 15:19:21.500] [I] ====================

[2014-06-12 15:19:21.500] [I] Name: Before Named Instance

[2014-06-12 15:19:21.500] [I] Id: 37

[2014-06-12 15:19:21.501] [I] Description:

[2014-06-12 15:19:21.501] [I] createTime: Mon Nov 11 2013 13:40:46 GMT-0500 (EST)

[2014-06-12 15:19:21.501] [I] quiesced: false

[2014-06-12 15:19:21.501] [I] replaySupported: null

[2014-06-12 15:19:21.502] [I] backupManifest: null

[2014-06-12 15:19:21.502] [I] snapshot id: snapshot-236

[2014-06-12 15:19:21.502] [I] state: poweredOff

[2014-06-12 15:19:21.502] [I]

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter