How to Set Up Azure Site Recovery Agent on Windows Server 2012 R2

Azure Site Recovery (ASR) is Microsoft’s disaster recovery service that replicates physical and virtual workloads to Azure, enabling failover to cloud infrastructure in the event of a primary site failure. For Windows Server 2012 R2 physical servers or on-premises VMs, ASR uses the Mobility Service agent (installed on the protected server) and a Configuration/Process Server to replicate data continuously to Azure. This guide focuses on the agent-based protection scenario for physical Windows Server 2012 R2 machines, covering the full setup: creating the ASR vault and replication policy, installing the Mobility Service agent, enabling replication, and testing failover.

Prerequisites

  • Windows Server 2012 R2 physical server or VM to be protected
  • An Azure subscription with sufficient quota for target virtual machine sizes
  • A Configuration Server (can be another WS2012 R2 VM) with outbound internet access
  • Target Azure Virtual Network and subnet pre-created
  • Outbound HTTPS access from the protected server to *.hypervrecoverymanager.windowsazure.com and *.backup.windowsazure.com
  • VSS (Volume Shadow Copy Service) enabled on the protected server

Step 1: Create an Azure Recovery Services Vault for ASR

Connect-AzAccount

$Location = "East US"
$ResourceGroup = "rg-asr-ws2012r2"
$VaultName = "rsv-asr-production"

New-AzResourceGroup -Name $ResourceGroup -Location $Location -Force

$Vault = New-AzRecoveryServicesVault -Name $VaultName `
    -ResourceGroupName $ResourceGroup `
    -Location $Location

Set-AzRecoveryServicesVaultContext -Vault $Vault

Write-Host "ASR Vault created: $($Vault.Name)"

Step 2: Create the Target Azure Infrastructure

Pre-create the Azure resources where the replicated server will run after failover:

# Create target resource group (for failover VMs)
New-AzResourceGroup -Name "rg-asr-failover" -Location $Location

# Create virtual network for failover VMs
$VNet = New-AzVirtualNetwork `
    -Name "vnet-asr-target" `
    -ResourceGroupName "rg-asr-failover" `
    -Location $Location `
    -AddressPrefix "10.10.0.0/16"

Add-AzVirtualNetworkSubnetConfig `
    -Name "subnet-servers" `
    -AddressPrefix "10.10.1.0/24" `
    -VirtualNetwork $VNet

$VNet | Set-AzVirtualNetwork

Write-Host "Azure target infrastructure created"

Step 3: Set Up the Configuration Server

The Configuration Server is a Windows Server machine that orchestrates replication between your on-premises servers and Azure. It runs the ASR Unified Setup, which installs the configuration server, process server, and master target server roles. On the Configuration Server machine:

# Download ASR Unified Setup on the Configuration Server
$UnifiedSetupUrl = "https://aka.ms/unifiedinstaller_wus2"  # Verify current URL from Azure Portal
Invoke-WebRequest -Uri $UnifiedSetupUrl -OutFile "C:TempMicrosoftAzureSiteRecoveryUnifiedSetup.exe"

Download the vault registration key from the Azure Portal: navigate to Recovery Services Vault > Site Recovery > Prepare Infrastructure > Source. Click Download registration key and save it to C:Tempvault_reg.key.

Run the Unified Setup on the Configuration Server:

Start-Process -FilePath "C:TempMicrosoftAzureSiteRecoveryUnifiedSetup.exe" -ArgumentList `
    "/AcceptThirdpartyEULA",
    "/ServerMode:CS",
    "/InstallLocation:`"C:Program Files (x86)Microsoft Azure Site Recovery`"",
    "/MySQLCredsFilePath:`"C:TempMySQLCreds.txt`"",
    "/VaultCredsFilePath:`"C:Tempvault_reg.key`"",
    "/EnvType:NonVMware" `
    -Wait

Step 4: Create a Replication Policy

Configure how frequently replication checkpoints are taken and how long recovery points are retained:

$Vault = Get-AzRecoveryServicesVault -Name "rsv-asr-production"
Set-AzRecoveryServicesVaultContext -Vault $Vault

$FabricName = "asr-fabric-onpremises"
$PolicyName = "asr-policy-24h-retention"

# Create the replication policy
$Policy = New-AzRecoveryServicesAsrPolicy `
    -Name $PolicyName `
    -ReplicationProvider "InMageRcm" `
    -RecoveryPointThresholdInMinutes 60 `
    -RecoveryPointRetentionInHours 24 `
    -ApplicationConsistentSnapshotFrequencyInHours 4

Write-Host "Replication policy created: $($Policy.FriendlyName)"

Step 5: Install the Mobility Service Agent on the Protected Server

The Mobility Service agent is installed on every server you want to protect with ASR. It intercepts all disk writes and sends them to the Process Server for replication to Azure. Install it from the Configuration Server’s shared folder:

# The Mobility Service installer is in the Configuration Server's installation directory
# Copy it from the Configuration Server (replace with actual Config Server IP):
$ConfigServer = "192.168.1.50"
$MobilityAgentPath = "\$ConfigServerASRShareSetupInMageInstallFilesUnifiedAgentMicrosoftAzureMobilityService.exe"

Copy-Item $MobilityAgentPath "C:TempMicrosoftAzureMobilityService.exe"

# Install the Mobility Service agent
Start-Process -FilePath "C:TempMicrosoftAzureMobilityService.exe" -ArgumentList `
    "/Role:`"Agent`"",
    "/InstallLocation:`"C:Program Files (x86)Microsoft Azure Site Recovery`"",
    "/CSIP:`"192.168.1.50`"",
    "/CSUserName:`"admin`"",
    "/CSPassword:`"ConfigServerPassword!`"",
    "/PassphraseFilePath:`"C:Temppassphrase.txt`"" `
    -Wait -PassThru

Write-Host "Mobility Service agent installed"

Verify the agent service is running:

Get-Service "InMage Scout Application Service" | Select-Object Name, Status
Get-Service "svagents" | Select-Object Name, Status

Step 6: Enable Replication for the Server

After the Mobility Service is installed and communicating with the Configuration Server, enable replication from the Azure Portal or PowerShell:

$ProtectableItem = Get-AzRecoveryServicesAsrProtectableItem -ProtectionContainer $ProtectionContainer -FriendlyName "$env:COMPUTERNAME"

# Enable replication to Azure
$Job = New-AzRecoveryServicesAsrReplicationProtectedItem `
    -ProtectableItem $ProtectableItem `
    -Name ($ProtectableItem.FriendlyName -replace " ","-") `
    -ProtectionContainerMapping $PolicyContainerMapping `
    -RecoveryAzureStorageAccountId $StorageAccount.Id `
    -RecoveryResourceGroupId $TargetResourceGroup.ResourceId `
    -RecoveryAzureNetworkId $VNet.Id `
    -RecoveryAzureSubnetName "subnet-servers" `
    -OS Windows `
    -OSDiskName ($ProtectableItem.Disks | Where-Object { $_.IsOSDisk }).Name `
    -RecoveryAzureVMSize "Standard_D2s_v3"

Write-Host "Replication enabled. Monitor progress in Azure Portal."

Step 7: Monitor Replication Status

# Check replication health
$ProtectedItem = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $ProtectionContainer

$ProtectedItem | Select-Object FriendlyName, ReplicationHealth, ReplicationState, `
    LastSuccessfulFailoverTime, LastReplicationTime, ProtectionStateDescription | Format-List

Step 8: Perform a Test Failover

Test failover validates that your server can be recovered in Azure without interrupting production replication. It creates a temporary VM in Azure using the latest recovery point:

$LatestRecoveryPoint = ($ProtectedItem | Get-AzRecoveryServicesAsrRecoveryPoint | Sort-Object RecoveryPointTime -Descending)[0]

$TestFailoverJob = Start-AzRecoveryServicesAsrTestFailoverJob `
    -ReplicationProtectedItem $ProtectedItem `
    -Direction PrimaryToRecovery `
    -AzureVMNetworkId $VNet.Id `
    -RecoveryPoint $LatestRecoveryPoint

Write-Host "Test failover initiated. Job ID: $($TestFailoverJob.Name)"

# After validating the test VM in Azure Portal, clean up the test failover:
Start-AzRecoveryServicesAsrTestFailoverCleanupJob `
    -ReplicationProtectedItem $ProtectedItem `
    -Comment "Test failover validated successfully on $(Get-Date -Format 'yyyy-MM-dd')"

Summary

Azure Site Recovery is now configured to replicate your Windows Server 2012 R2 machine to Azure. The setup includes a Recovery Services Vault, target Azure virtual network for failover, a Configuration Server orchestrating replication, the Mobility Service agent installed on the protected server with continuous replication, and a replication policy with 24-hour recovery point retention and application-consistent snapshots every 4 hours. Periodic test failovers validate that the server can be recovered in Azure within the target RTO (Recovery Time Objective), providing confidence in the disaster recovery capability without impacting production operations.