VMware {code} Community
gsangle
Contributor
Contributor

How to figure out if a VM is being backed up

Hello,

I have written a script to unregister VMs after the backup software is done backing up the VM

My script keeps running every so often, gets the list of VMs and then un-registers them.

However, I want to fail the unregister operation if the VM is being backed up.

For that, I need to figure a way if the VM is being backed up. I have a couple of ideas:

- Find the snapshot creation time (easily available) and check if newer than last operation I did on the VM (which is rename operation).

Question : Using the SDK, how do i figure out if the time of the last rename operation ?

- Any other idea to figure out if the VM is being backed up ?

Reply
0 Kudos
3 Replies
stumpr
Virtuoso
Virtuoso

That's a good way to go about it.  You can query the tasks and get the Rename_Task().    You'll have to do a CreateCollectorForTasks and specify the task type (Rename_Task).  They are basically ordered sequentially, so grab the most recent one.  You can also add a filter item to your collector rule that only targets that VM as well.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
gsangle
Contributor
Contributor

Thanks for you reply ...

I tried this:

    my $TaskManager = Vim::get_view( mo_ref => Vim::get_service_content()->taskManager );

    my $TaskFilterSpecByEntity = TaskFilterSpecByEntity->new(

               entity => $vm,

               recursion => TaskFilterSpecRecursionOption->new("self"),

               );

    my $TaskFilterSpec = TaskFilterSpec->new(

                         entity => $TaskFilterSpecByEntity );

    my $TaskHistoryCollector_mor = $TaskManager->CreateCollectorForTasks(

                                   filter => $TaskFilterSpec );

    my $TaskHistoryCollector = Vim::get_view ( mo_ref => $TaskHistoryCollector_mor );

However, it gives me an exception:

SOAP Fault: ----------- Fault string: The operation is not supported on the object. Fault detail: NotSupportedFault

Reply
0 Kudos
CoinGrahamIV
Contributor
Contributor

This last line is unnecessary right?  You're trying to grab a managed object reference when you already have it.

   my $TaskHistoryCollector = Vim::get_view ( mo_ref => $TaskHistoryCollector_mor );

Just set to the "latestPage" and start "ReadPreviousTasks" until you find what you're looking for.

Reply
0 Kudos