HyperV: How to enable Resilient change tracking for hyperv backup with c#?

Haniel Arce Manriquez 1 Reputation point
2022-02-16T22:20:23.497+00:00

Hello
I am trying to create a Net 5.0 application for Hyper-v Backup and I would like to use Resilient Change Tracking for backup virtual disk's Blocks changing.

I am using a Wrapper to library VirtDisk.h (https://video2.skills-academy.com/en-us/windows/win32/api/virtdisk/) from C# to access Win32 Resilient Change Tracking functions and also I am testing with Windows server 2016 version 1607 with Hyper-v version 8.0, by default when I create a virtual machine Resilient Change Tracking is disabled, so I have to enable it, but never gets activated.

The test hyper-v host machine (Windows server 2016) is a single server and is not in a cluster.

To activate Resilient Change Tracking through VirtDisk.h, I am calling the function SetVirtualDiskInformation:

[DllImport("VirtDisk.h", CharSet = CharSet.Unicode)]  
public static Win32Error SetVirtualDiskInformation(VIRTUAL_DISK_HANDLE VirtualDiskHandle, in SET_VIRTUAL_DISK_INFO VirtualDiskInfo);  

VIRTUAL_DISK_HANDLE is a pointer (SafeHandler) to a VirtualDisk that was obtained by calling the OpenVirtualDisk method of the VirtDisk.h

[DllImport("VirtDisk.h", CharSet = CharSet.Unicode)]  
public static Win32Error OpenVirtualDisk(in VIRTUAL_STORAGE_TYPE VirtualStorageType, string Path, VIRTUAL_DISK_ACCESS_MASK VirtualDiskAccessMask, OPEN_VIRTUAL_DISK_FLAG Flags, OPEN_VIRTUAL_DISK_PARAMETERS Parameters, out SafeVIRTUAL_DISK_HANDLE Handle);  

Code to open virtual disk:

   string vhdxPath = @"A:\VirtualMachine\VirtualDisk.vhdx";  
       OPEN_VIRTUAL_DISK_PARAMETERS parameters = new OPEN_VIRTUAL_DISK_PARAMETERS(1)  
       {  
           Version = OPEN_VIRTUAL_DISK_VERSION.OPEN_VIRTUAL_DISK_VERSION_1,  
       };  
       parameters.Version1.RWDepth = 1;  
       var vhd = VirtualDisk.Open(vhdxPath, OPEN_VIRTUAL_DISK_FLAG.OPEN_VIRTUAL_DISK_FLAG_NONE, parameters, VIRTUAL_DISK_ACCESS_MASK.VIRTUAL_DISK_ACCESS_ALL);  
     
   VIRTUAL_DISK_HANDLE is a pointer that is obtained without problems and I can access the virtual disk information through all the functions of VirtDisk.h, however when I try to activate Resilient Change Tracking with the following code, it never works  
     
       var si = new SET_VIRTUAL_DISK_INFO { Version = SET_VIRTUAL_DISK_INFO_VERSION.SET_VIRTUAL_DISK_INFO_CHANGE_TRACKING_STATE, ChangeTrackingEnabled = true };  
       var result = SetVirtualDiskInformation(Handle, si);  
       result.ThrowIfFailed();  
     
   Finally, I validate the ChangeTrackingEnabled property after activating it and it always has a false value, also the files with the .rct extension are never generated.  
   I wonder if there is another way or example code or documentation for activate Resilient Change Tracking inside a virtual machine?  
     
   NOTE: I tried activate Resilient Change Tracking using powershell with the command Update-VMVersion and I get the following message;  
     
   > WARNING: No update was performed for the virtual machine "MVWinRctTest" because its configuration version is already at the maximum level supported by this server.  For clustered servers, the maximum supported configuration version can be limited by the cluster functional level.  
     
   Any thoughts will be greatly appreciated.  
   Best
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,499 questions
Hyper-V
Hyper-V
A Windows technology providing a hypervisor-based virtualization solution enabling customers to consolidate workloads onto a single server.
2,610 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,571 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,612 questions
Windows Server Backup
Windows Server Backup
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Backup: A duplicate copy of a program, a disk, or data, made either for archiving purposes or for safeguarding valuable files from loss should the active copy be damaged or destroyed.
464 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. quentus gou 0 Reputation points
    2023-12-18T05:55:27.48+00:00

    hi Haniel Arce Manriquez

    After my testing, there is no problem with your code. Just specify that ChangeTrackingSupported=true as displayed here:

    var si = new SET_VIRTUAL_DISK_INFO { Version = SET_VIRTUAL_DISK_INFO_VERSION.SET_VIRTUAL_DISK_INFO_CHANGE_TRACKING_STATE, ChangeTrackingEnabled = true };
      
    si.ChangeTrackingEnabled = true; //The assignment in the new operation above is invalid and must be assigned separately
    
    var result = SetVirtualDiskInformation(Handle, si);  
    result.ThrowIfFailed();  
    
    0 comments No comments