VMware Cloud Community
Peregrin
Contributor
Contributor
Jump to solution

Problem with Remove-Snapshot cmdlet

Hello everybody,

I have a problem with the Remove-Snapshot cmdlet: It fails to remove the snapshot when I have done a file copy (Copy-Item) between the calls to New-Snapshot and Remove-Snapshot if (and only if) I set -Confirm option to $false. If -Confirm is $true everything works but this will not allow me to run the script non-interactive. The error that is thrown is "vim.fault.InvalidVmConfig".

Does anybody know if this is a problem on my side, on ESX server side or a bug in VI Toolkit? Any possible work-arounds?

I have attached the PowerShell script I used to reproduce the error and the script log file that contains the error message.

The versions I used are:

VMware.Vim.dll (1.5.0.1299, "VI API .Net 1.5.0 build 142961")

VMware ESX Server 3i, 3.5.0, 110271

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
yboychev
Hot Shot
Hot Shot
Jump to solution

I'm not able to reproduce this on my environment but I'm pretty sure the issue is not with the -Confirm:$false parameter. After you copy the file there is a timeout whivh is set to 10 seconds. Can you increase this (although I don't see a reason for this timeout at all) and see what will happen?

\Yavor

View solution in original post

0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Quick question, on what type of datastore, LUN (FC, iSCSI, local SCSI) or NFS, is the guest stored ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Peregrin
Contributor
Contributor
Jump to solution

The guest is stored on a fileserver (Ubuntu GNU/Linux). ESX server accesses the datastore via NFS. The machine running the script has access on files in the datastore via CIFS (Samba).

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Couldn't reproduce your problem on a LUN-based datastore.

And I have no access to NFS datastores for the time being.

Do the permissions on the file you added look ok (owner,group,chmod mask) ?

I experienced ACL problems when using mixed-mode (NFS-CIFS) access to files in the past.

But I agree that wouldn't explain the -Confirm parameter behaviour.

Anything in the vmware.log file ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Peregrin
Contributor
Contributor
Jump to solution

Yes, the file permissions look OK. And I forgot to mention that the datastore is available read-only via CIFS. So only the ESX server is able to write to files in the datastore, not the machine where the script is running and performing the Copy-Item.

Also I should note that after the Remove-Snapshot fails it is possible without problems to remove the snapshot by hand using VMware Infrastructure Client (Version 2.5.0 Build 103682). The vmware.log seems to contain nothing about the failing Remove-Snapshot, I have nevertheless added the lines for one run of the script where -Confirm was set to $false.

0 Kudos
Peregrin
Contributor
Contributor
Jump to solution

I have found some kind of work-around now: When I run a second script after the one that created the snapshot it is possible to remove the snapshot without a confirmation and without triggering the stated error.

The second script basically just contains:

Connect-VIServer ...

$vm = Get-VM ...

$snapshot = Get-Snapshot -VM $vm -Name BackupSnapshot

if ($snapshot)

{

Write-Host "Reverting old backup snapshot..."

Remove-Snapshot -Snapshot $snapshot -Confirm:$false -RunAsync:$false

}

I also tried to close and reconnect before removing the snapshot directly in the main script but this did not work well.

0 Kudos
admin
Immortal
Immortal
Jump to solution

This looks like some sort of timing problem. I have to wonder though why you're doing this. Can't you just copy the VMX file without snapshotting the VM? Snapshots don't change the VMX in any way that I know of.

0 Kudos
yboychev
Hot Shot
Hot Shot
Jump to solution

I'm not able to reproduce this on my environment but I'm pretty sure the issue is not with the -Confirm:$false parameter. After you copy the file there is a timeout whivh is set to 10 seconds. Can you increase this (although I don't see a reason for this timeout at all) and see what will happen?

\Yavor

0 Kudos
yboychev
Hot Shot
Hot Shot
Jump to solution

I also have some comments/suggestions to your script:

1. $vm = Get-VM | Where-Object { $_.Name -eq "Frogstar-A"} is equivilent to much simpler form $vm = Get-VM "Frogstar-A"

2. $snapshot = New-Snapshot -VM $vm -Name BackupSnapshot -Confirm:$false -RunAsync:$false -Quiesce:$true : There is no need to specify -RunAsync:$false. It is the default behavior for all cmdlets

3. Copy-Item $srcfile -Destination $dstfile -Force -Container: There is an option to that without the samba share using the ViToolkit. It is not trivial but it is an option to research if the samba shares are an overhead for you. You can look for CopyDatastoreFile_Task() method in the SDK documentation available here: http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide.

4 . Write-Host "Reverting the snapshot..."

Remove-Snapshot -Snapshot $snapshot -Confirm:$false -RunAsync:$false

Actually Remove-Snapshot just removes the snapshot. It does not revert the vm to the state of the snapshot in case this is your intend. To do that you have to call Set-Vm cmdlet using the -Snapshot parameter.

Again these are just suggestions.

Hope this will help,

\Yavor

0 Kudos
Peregrin
Contributor
Contributor
Jump to solution

Seems to be some timing issue indeed. When I set the sleep time before the call to Remove-Snapshot to 30 seconds it works.

When running a test where the sleep time was set to 20 seconds I got a different error message:

Remove-Snapshot : 15.04.2009 10:46:48 Remove-Snapshot 5291e24e-fc4d-6e02-6f49-20e4ecaefeed The operation for the entity 144 failed with the following message: "A general system error occurred: Internal error"

At C:\Documents and Settings\admin\Desktop\VMWare+PowerShell\VMware-Backup.ps1:168 char:22

+ Remove-Snapshot <<<< -Snapshot $snapshot -Confirm:$false -RunAsync:$false

Don't know why there is some sleep time necessary and if it will work reliably when using 30s but I think I can live with this work-around.

0 Kudos