image
If you don’t know what Changed Block Tracking is, just read this excellent post from Eric Siebert.

You can check the status of Changed Block Tracking with the following PowerCLI one-liner:

Get-VM | Get-View | `
Sort Name | Select Name, `
@{N="ChangeTrackingStatus";E={$_.Config.ChangeTrackingEnabled}}

The output of the one-liner will look like this:

image

If you’re running a VM with only one VMDK, you can use the following function to enable Changed Block Tracking:

Function EnableChangeTracking{
    param($vm)
    $vmView = Get-VM $vm | Get-View

    if($vmView.Config.Version -eq "vmx-04"){
        Write-Host -ForegroundColor Red `
        "The Virtual Hardware version of this VM does not support Changed Block Tracking"
        return
        }

    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.changeTrackingEnabled = $true
    $vmView.ReconfigVM($vmConfigSpec)

    sleep 3

    Get-VM $vm | New-Snapshot -Name "Temp" 

    sleep 5

    Get-VM $vm | Get-Snapshot | Where {$_.Name -eq "Temp"} | Remove-Snapshot -Confirm:$false
}

You can run the function via the following command:

image

I am going to updated the function later, so it will be able to enable Changed Block Tracking on a VM with multiple VMDKs.

Update: When the VM is powered off, you are able to set the Changed Block Tracking feature for all the VMDKs.

Update 2: There was a little chat about this subject on Twitter between @lamw @gabvirtualworld and me (@afokkema) where @gabvirtualworld posted the following tweet:

image

I can confirm this theory and update my script with this little trick. Now you’re able to enable Changed Block Tracking when your VM is powered on.

9 thoughts on “PowerCLI: Enable Changed Block Tracking

  1. Actually if you’re enabling CBT using API and the VM is running HW7 and is poweredOff, it should add entries for all VMDK(s) for your VM and create the ctkEnabled to true. If you set it to disable, then you’ll just get “false” entries in your .vmx file.

    Take a look at at this vSphere SDK for Perl http://communities.vmware.com/docs/DOC-11642 that does exactly that which I believe you’re already doing, so you shouldn’t have to do anything special for a VM that has 1 VMDK or 10 VMDKs

    –William

  2. Just tried this with vSphere 4.0U1 / VDR 1.1:

    I just used your one-liner and it listed all VMs that are associated with a VDR backup schedule as being TRUE. All VMs not associated were listed as being FALSE. I created a new backup job with four new VMs. Once the first backup job finished, the four new VMs listed as TRUE.

    It looks like your function is not needed since it appears as if VDR enables CBT automagically now.
    Dave

  3. Hi guys,

    I am using netbackup 7 Block Level Incremental Backup feature. When you run the backup, VMs cbt configuration is enabled by Netbackup automatically. I also heard from a Veeam engineer that they also enable this automatically. So I suggest check with your backup product vendor or documentation before you start using powercli to enable this feature.

    Burak Uysal
    Storage Consultant

  4. I am looking to update CBT on the VMs in my environment and I was just wondering what would need to be added to make this work on VMs with more than one VMDK?

  5. I used above command and it worked only for disable ($false), when I set enable ($true), Ctkenabled still have value false from vsphere client

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.