Enabling Change Block Tracking (CBT) on a vSphere 5.1 VM with PowerShell/PowerCli

2013/07/02 | 3 minute read |

In one of my previous post, I created two PowerShell functions to enable Copy/Paste operations on VMware vSphere 5.1 between a Guest OS and the vSphere Client remote console. Today we’ll use a very similar piece of code to Enable Change Block Tracking (CBT) on one or more Virtual Machines.

I already talked about CBT in the past, but I just wanted to create re-usable PowerShell functions that will help me when I need it.

What is Change Block Tracking again?

Changed Block Tracking (CBT) is a feature from VMware used for Virtual Machine incremental backup. Similar to snapshot differentials or delta differencing, Change Block Tracking backs up only the blocks that have changed, rather than backing up every block of every VM in the infrastructure.

CBT requires :

  • VMware ESX/ESXi hosts at version 4.0 at least or newer,

  • Virtual Machine(s) must be at the virtual hardware version 7 or newer,

  • Input/Output (I/O) operations go through the ESX/ESXi storage stack:

  • NFS Supported

  • VMFS Supported (Local disk, SAN or iSCSI)

  • RDM in virtual compatibility mode Supported

  • RDM in physical compatibility mode NOT Supported

  • CBT must be enable for the Virtual Machine,

  • Virtual Machine storage must not be (persistent or non-persistent) independent disk (unaffected by snapshots),

  • Finally the Virtual Machine must go through a stun-unstun cycle (power on, resume after suspend, migrate, or snapshot create/delete/revert) before the reconfiguration takes effect.

For CBT to identify disk sectors in use with the special "*" change ID, the following are required:

  • The virtual disk must be located on a VMFS volume, backed by SAN, iSCSI, or local disk. RDM is not VMFS,

  • The virtual machine must have zero snapshot when CBT is enabled.

Other Important points about CBT:

By default the Change Block Tracking (CBT) is disabled.

Administrators can enable CBT and some backup tools enable it automatically (It was the case for me using Symantec NetBackup). If any blocks were changed since the last backup, Changed Block Tracking tags them and stores the information in a CTK file in the Virtual Machine folder by default. CBT tells the vSphere or third-party backup tool to copy these changed blocks, avoiding copies of the entire VM. This reduces the amount of data undergoing backup.

Once enabled, the three following entries will appear in the “Configuration Parameters” values of the Virtual Machine.

This enable CBT on your VM. ctkEnabled= true</td></tr></tbody></table>
Additionally, you will have an entry for each disk. (in this example I had two virtual disks) scsi0:0.ctkEnabled= true scsi0:1.ctkEnabled= true</td></tr></tbody></table>VMware acknowledges that CBT could reset or lose track of incremental changes in the event of a power failure or hard shutdown. In vSphere 4.1 and prior, Cold Migration (but not Storage vMotion) could reset but not disable CBT. In vSphere 5.x, Storage vMotion will reset CBT. PowerShell Obviously you will need VMware PowerCli ; Here I used PowerCli version 5.1 with PowerShell 3.0. Download VMware PowerCli Download PowerShell 3.0 Set-VMChangeBlockTracking</b> Here is the small piece of the script that actually does the change (download the full script a bit below) ``` PROCESS{ TRY{ foreach ($item in $vm){ Write-Verbose -Message "$item - Setting the Change Block Tracking Setting to $Enable..." $CurrentVM = Get-vm $item | get-view $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec $vmConfigSpec.changeTrackingEnabled = $true $CurrentVM.reconfigVM($vmConfigSpec) }#foreach }# TRY Block CATCH{ Write-Warning -Message "Wow Something went wrong with $item" }#CATCH Block }#PROCESS Block ``` Again, Once your enabled CBT, your VM will need to go through astun-unstuncycle (power on, resume after suspend, migrate, or snapshot create/delete/revert) before the reconfiguration takes effect. Download Technet Repository Resources * VMware:Enabling Changed Block Tracking (CBT) on virtual machines (1031873) * LazyWinAdmin:Enabling Change Block Tracking (CBT) on a Virtual Machine (VMware vSphere 5.1)

Leave a comment