Changed Block Tracking (CBT) is a key technology used by VMware to implement incremental backups. The primary advantage of CBT is its ability to save storage space by allowing only modified data blocks to be backed up, rather than requiring a full backup of the entire virtual machine each time. When CBT is enabled, a -ctk.vmdk
file is created in the virtual machine’s storage directory to record changes. However, enabling CBT may lead to a slight performance loss, which is why it is turned off by default.
How It Works
CBT monitors which data blocks have changed since the last snapshot and records their offsets, allowing it to track data modifications. Environments that support CBT include virtual disks stored on VMFS or NFS, as well as RDM in virtual compatibility mode. However, physical compatibility mode RDM does not support this feature. To enable CBT, the virtual machine must be version 7 or higher, and you can check support for CBT through the PropertyCollector of the VirtualMachine ManagedObject.
Enabling and Setting Up CBT
CBT can be enabled through two methods: programmatic and manual. Programmatically, you can use the following code:
VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
configSpec.changeTrackingEnabled = new Boolean(true);
ManagedObjectReference taskMoRef = serviceConnection.getService().ReconfigVm_Task(targetVM_MoRef, configSpec);
To enable CBT manually, right-click the virtual machine, select “Edit Settings,” and find the “ctkEnabled” option under “Advanced” to enable it.
Obtaining Modified Data Block Offsets
The QueryChangedDiskAreas
method allows you to retrieve CBT information, requiring parameters such as the target virtual machine, snapshot, and disk details. The returned DiskChangeInfo
object contains the offsets and lengths of the modified data blocks, helping developers identify which data needs to be backed up.
Change Identifier (changeId)
The changeId
is a state identifier for the virtual disk at a specific point in time. Initially, it is set to none
when the first snapshot is created. When calling the QueryChangedDiskAreas
method, if changeId
is set to *
, it indicates that all allocated areas should be retrieved, but this is only valid when the virtual machine has just one snapshot.
Application Scenarios and Example
In practice, the initial full backup records the virtual machine’s configuration and creates a snapshot. Subsequent incremental backups utilize the QueryChangedDiskAreas
method to get modified data since the last snapshot. By effectively leveraging CBT and related methods, you can streamline the backup process, reducing time and resource consumption.
In summary, CBT is a powerful backup solution provided by VMware that significantly enhances the efficiency of incremental backups, helping users manage data more effectively in virtualized environments.