You dont have javascript enabled! Please enable it!

Remove Lingering Hyper-V Replica Log (HRL) File From #HyperV

4 Min. Read

In this article, we will show you how to remove lingering Hyper-V replica logfile from a Virtual Machine that was not properly removed after removing VM Replication on Windows Server 2016 Hyper-V.

The same will apply whether you are using Windows Server 2019 or a later release.

Introduction

Sometimes things go wrong with Hyper-V Replica. There are many reasons for this, but one of the reasons is when you are running out of disk space on the replica side.

Are you monitoring your Hyper-V Replica infrastructure? If not, then make sure to check this article: <Advanced Hyper-V Replica Monitoring using PowerShell>.

A little bit of context on how Hyper-V replica works behind the scene, Hyper-V replica creates a checkpoint (.avhdx) to handle the initial replication of the virtual machine (for example when getting the first copy of the virtual machine across the replica host). Hyper-V Replica will merge this disk out once it has successfully made a full copy of the virtual machine, the virtual hard disk (which can take a while).

Remove Lingering Hyper-V Replica Log (HRL) File From #HyperV 1

As you can see in the above screenshot, the replication is not enabled for this virtual machine, in fact, I removed all replication using the Remove-VMReplication cmdlet when the replication health was in a critical state.

If we look at the virtual hard disk files of the VM, we see the traces of a Windows Server 2012R2 Hyper-V replica (HRL Hyper-V replica log).

Remove Lingering Hyper-V Replica Log (HRL) File From #HyperV 2

Did you notice the HRL file size is large 32 GB?

A quick overview of HRL

Once the initial replication of a VM is completed, Hyper-V Replica will start monitoring the changes of each selected virtual hard disk. This is done by mirroring the changes to a Hyper-V Replica Log (HRL) file. The HRL files are kept in the same directory where Virtual Machine VHDX files reside. Each VHDX file, which has been selected for the replication, has an associated HRL file. The changes are tracked at the Virtual Machine level e.g. any changes (write operations) to the virtual machine are tracked and stored in the Hyper-V Replication Log files.

Once the replicas/HRL files are ready, “Replication Manager” notifies “Replication Tracker” (RT) to send the copies to the Replica Server. The changes are tracked on the Primary Server and the Change Tracking component has no function on the Replica Server!

The question is, why the size of the log file (.HRL) is growing from MBs to GBs? if you want to identify the guest processes that cause large log files, then make sure to download (Hyper-V Replica Identify Script) from TechNet and run it inside the guest OS, this script provides debugging information that will help you to identify what is going on in the guest that causes large log files in Hyper-V Replica.

As Best Practice, please make sure to create a new VHD(x) file, one for each VM, and move the paging files to those volumes. when you set up Hyper-V replication, do NOT select the box next to that volume.

Also, if you have any VM that hosts SQL Server, then move the TempDB files to a separate VHD(x) file as well, and don’t replicate that one, because every time you start a new server or new SQL instance, the paging files and Temp DBs are empty, so nothing is lost if you failover to the replica side.

If you look at all the remaining HRL files on the host, we can see around 81GB of disk space.

Remove Lingering Hyper-V Replica Log (HRL) File From #HyperV 3

Remove Lingering Hyper-V Replica

You can delete each HRL log file manually as long as the VM replication is removed.
PowerShell to the rescue!

Get-ChildItem -File -Path D:\ -Filter *.HRL -Recurse | Remove-Item –Force

Remove Lingering Hyper-V Replica Log (HRL) File From #HyperV 4

Here is another PowerShell snippet to delete older lingering HRL files due to past issues and keep the current ones so the Hyper-V replica won’t break:

$Source = "D:\VirtualMachines\"
Get-ChildItem -File -Path $Source -Filter *.HRL -Recurse
Get-ChildItem -File -Path $Source -Filter *.HRL -Recurse | Where-Object {$_.LastWriteTime.Day -ne "$(Get-date -UFormat %e)"}
Get-ChildItem -File -Path $Source -Filter *.HRL -Recurse | Where-Object {$_.LastWriteTime.Day -ne "$(Get-date -UFormat %e)"} | Remove-Item -Force
Get-ChildItem -File -Path $Source -Filter *.HRL -Recurse

As a side note: If you are backing up virtual machines running on Windows Server 2016 Hyper-V or later, you will see two new files, the MRT (Modified Region Table) file, and RCT (Resilient Change Tracking) which keep track of all the changed blocks and travel with each (VHDX/AVHDX) if a virtual machine is moved to another Hyper-V host or to another storage.

Moreover, if the Get-ChildItem command didn’t return any results, the HRL files could be still locked by Hyper-V, you need to shut the VM down and then run the commands above.

If you come across a scenario where you want to delete the MRT and RCT files, then you can use the same script described above to remove unused MRT/RCT files as well.

However, in a normal situation, you should not touch those files as long as the virtual machine is protected by a backup application such as (DPM, MABS, VEEAM, etc.). The size of the MRT and RCT files is very small less than < 100 KB.

Conclusion

Keep monitoring your Hyper-V Replica / Backup and start removing the lingering HRL log files and free up some disk space.

Do you want to know more about RCT and MRT files in Windows Server 2016 Hyper-V including backup architecture and the difference between different versions? I strongly recommend checking my recently published book Windows Server 2016 Hyper-V Cookbook – Second Edition!

Cheers,
-Charbel

Related Posts

Previous

Savision Launched Live Maps Unity 7.5

Join Packt and Prepare for Tech in 2016 @PacktPub

Next

7 thoughts on “Remove Lingering Hyper-V Replica Log (HRL) File From #HyperV”

Leave a comment...

  1. Here you point out that you can remove the HRL files as long the as the VM replication is removed. Could you elaborate on that? In my setup there is a live Hyper-V sync running and don’t want to break that, yet there are for sure lingering HRL files due to past issues. How should I proceed with the PS command?

  2. Hello Joey,

    Here is the PowerShell command to delete older lingering HRL files due to past issues and keep the current ones so the replica won’t break.

    $Source = “D:\VirtualMachines\”
    Get-ChildItem -File -Path $Source -Filter *.HRL -Recurse
    Get-ChildItem -File -Path $Source -Filter *.HRL -Recurse | Where-Object {$_.LastWriteTime.Day -ne “$(Get-date -UFormat %e)”}
    Get-ChildItem -File -Path $Source -Filter *.HRL -Recurse | Where-Object {$_.LastWriteTime.Day -ne “$(Get-date -UFormat %e)”} | Remove-Item -Force
    Get-ChildItem -File -Path $Source -Filter *.HRL -Recurse

    Here is the screenshot.

    Hyper-V Replica Old HRL Files

    Hope this helps!

    Cheers,
    -Charbel

  3. Hey Charbel,

    It worked like a charm, old HRL files removed and replication still works.

    Thanks!

  4. Hi Charbel,

    Thank you for your PowerShell script, was able to recover disk space without disrupting the replication process.
    Minhaj.

  5. Hello Minhaj, thank you for the feedback much appreciated!
    I am happy to hear that the steps provided here were helpful to you to recover disk space without disrupting the replication process.
    All the best,

  6. I had to use this procedure on a VM that had replication removed weeks prior, but oddly the .hrl files were not removed and still kept growing. Get-ChildItem command didn’t work as the files were locked, I had to shut the VM down and then run the command. It worked perfectly then, and VM booted fine after.

    Saved so much space now.

    Cheers!!!

  7. Hello Steve, thank you for the feedback much appreciated!
    I am happy to hear that the steps provided here were helpful to recover your disk space.
    Cheers!!!

Let me know what you think, or ask a question...

error: Alert: The content of this website is copyrighted from being plagiarized! You can copy from the 'Code Blocks' in 'Black' by selecting the Code. Thank You!