Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Active Directory / Backing Up Active Directory with Windows Server Backup

November 26, 2024 Active DirectoryPowerShellWindows Server 2022

Backing Up Active Directory with Windows Server Backup

In this article, we’ll cover how to back up Active Directory domain controllers and enable automatic AD backups using PowerShell and the built-in Windows Server Backup feature.

Contents:
  • Do I Need to Backup Active Directory?
  • Get the Last Backup Time of Active Directory Domain Controller
  • How to Backup AD Domain Controller with Windows Server Backup
  • Backup Active Directory with a PowerShell Script

Do I Need to Backup Active Directory?

One way to improve fault tolerance and load balancing in Active Directory is to deploy additional domain controllers. In such an environment, the AD database is replicated between all DCs. If one of the DCs fails, the entire directory service will not fail.  Domain clients can easily switch to the domain controllers that are still alive. The administrator can quickly deploy a new DC, replicate the AD database from the remaining DCs, and then remove the failed domain controller.

However, additional domain controllers will not help in cases where all DCs are broken. For example, if all domain controllers are infected or encrypted (for instance,  after the domain administrator’s credentials have been intercepted by using the Mimikatz tool), if the logical structure of the NTDS.DIT database (replicated to all DCs) is corrupted or in other catastrophic scenarios.

In general, backing up to AD is absolutely necessary. At a minimum, you should regularly back up DCs that hold Flexible Single-Master Operations (FSMO) roles. List the domain controllers running the FSMO roles using the command:

netdom query fsmo

Get the Last Backup Time of Active Directory Domain Controller

Use the repadmin command to see when the current AD domain controller was last backed up:

repadmin /showbackup

In this example, the last time the DC and AD partitions were backed up was in 2021 (most likely, it hasn’t been done since the domain controller was deployed.).

repadmin check Acrive Directory domain controller last backup time

Get the last backup time for each DC in the domain:

repadmin /showbackup *

Use the following command to find out how many times AD has been backed up on a specific DC:

(Get-ADReplicationAttributeMetadata -Object "CN=Configuration,DC=WOSHUB,DC=LOC" -Properties dSASignature -Server M-DC01).Version

If your domain controllers are virtualized and backed up via snapshots (see the example with Hyper-V backup), make sure that your backup software updates the LastOriginatingChangeTime attribute value in LDAP (it contains the date of the last backup).

How to Backup AD Domain Controller with Windows Server Backup

If you don’t have special backup software, use the built-in Windows Server Backup (WSB) feature (which replaces the NTBackup tool) to backup Active Directory.

To back up a domain controller, create a System State backup of Windows Server on the DC. The System State backup includes the Active Directory database (NTDS.DIT), the contents of the SYSVOL directory including the Group Policy (GPO) files, integrated DNS zones, the registry, IIS metadata, the AD CS database, the Windows bootloader configuration, and other system files and resources. The backup is created through the Volume Shadow Copy Service (VSS).

Use the Get-WindowsFeature PowerShell cmdlet to verify that the Windows Server Backup feature is installed:

Get-WindowsFeature Windows-Server-Backup

WindowsFeature Windows-Server-Backup

If WSB is not installed, add it with PowerShell:

Add-Windowsfeature Windows-Server-Backup –Includeallsubfeature

Or install the Windows Server Backup via Server Manager -> Features.

Windows Server Backup feature install via server manager

I want to back up this AD domain controller to a shared network folder on a remote file server. For example, a path to the backup directory might look like this: \\mun-back1\backup\dc01. Change the NTFS permissions on this share so that only SYSTEM, Domain Admins, and Domain Controllers can read/write to the directory. backup ad domain controller to a shared folder

An administrator can use the Windows Server Backup graphical MMC snap-in (wbadmin.msc) to configure and enable an automatic AD backup task. The main disadvantage of this method is that a new AD backup always overwrites a previous one in the WindowsImageBackup directory.  Use the wbadmin.exe command-line tool to automate backup creation if you want to have AD backups from different dates.

Backup Active Directory with a PowerShell Script

Let’s use a PowerShell script to automate the domain controller backup. To have multiple copies of AD backups, we will put each backup in a separate folder. The name of the folder will be the date on which the copy was created.

When backing up to a shared folder, only the full Windows Server backup mode is supported. When a backup drive is connected as a local device (for example, LUN over FC or iSCSI disk), VSS supports incremental backup mode for such a device.

A basic version of a PowerShell script to backup DC might look like this

$path="\\mun-back1\backup\dc1\"
Import-Module ServerManager
[string]$date = get-date -f 'yyyy-MM-dd'
$TargetUNC=$path+$date
$TestTargetUNC= Test-Path -Path $TargetUNC
if (!($TestTargetUNC)){
New-Item -Path $TargetUNC -ItemType directory
}
$WBadmin_cmd = "wbadmin.exe START BACKUP -backupTarget:$TargetUNC -systemState -noverify -vssCopy -quiet"
Invoke-Expression $WBadmin_cmd

In addition, you can add a PowerShell function that logs all of the actions to a text file.

Add the following code to have the PowerShell script delete old backup versions (for example, older than 90 days):

$Period = "-90" # Number of days
# Calculate the date after which you want to delete the old backups
$CurrentDay = Get-Date
$ChDaysDel = $CurrentDay.AddDays($Period)
# Delete files created more than a specified number of days ago
GCI -Path $TargetUNC -Recurse | Where-Object {$_.CreationTime -LT $ChDaysDel} | RI -Recurse -Force
# Deleting empty folders
GCI -Path $TargetUNC -Recurse | Where-Object {$_.PSIsContainer -and @(Get-ChildItem -Path $_.Fullname -Recurse | Where { -not $_.PSIsContainer }).Count -eq 0 } | RI -Recurse

If you are backing up to a locally attached drive, instead of using such a script, you can use the command to properly delete old backup versions:
$KeepVersion=10
$WBadmin_cmd = " wbadmin delete backup -keepVersions:$KeepVersion -quiet"
Invoke-Expression $WBadmin_cmd

In this case, wbadmin will only keep the 10 most recent backups. More older backups will be deleted.

Run this script. Information about creating a shadow copy of the hard disk should appear in the wbadmin console.

powershell script backup active directory dc with wbadmin tool

If the backup is successful, the following messages will appear in the log:

The backup of volume (C:) completed successfully.
The backup of the system state successfully completed.

The full Windows Server Backup log is available in the directory C:\Windows\Logs\WindowsServerBackup\.

AD DC backup Windows Server Backup log

Now check that the DC’s last backup date is updated:

repadmin /showbackup

Now it says that the last domain controller backup was performed today.

repadmin /showbackup check if dc backed up

The size of the DC backup on the shared share in this example is approximately 12 GB. The result will be a VHDX image file with a DC backup that can be used for OS recovery via WSB, or you can manually mount the VHDX file and extract the required files or folders from it.

vhdx file with AD DC backup

If there are multiple DCs on the AD site, it is not necessary to backup them all. To save space, it is sufficient to periodically back up only the AD database file (ntds.dit). To do it, use these commands:

$WBadmin_cmd = "wbadmin start backup -backuptarget:$path -include:C:\Windows\NTDS\ntds.dit -quiet"
Invoke-Expression $WBadmin_cmd

Depending on the size of the AD database, the size of such a backup will be only 50-500 MB.

To perform an automatic AD backup, create c:\ps\backup_ad.ps1 script on your DC. This PowerShell script must be run through the Task Scheduler. You can create a scheduled task from the taskschd.msc GUI or with PowerShell. This task must be run on behalf of S the NT AUTHORITY\SYSTEM with the Run with highest privileges option enabled. Create the following scheduled task to back up the AD domain controller three times a week:

$trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Tuesday,Friday -At "01:00AM"
$User= "NT AUTHORITY\SYSTEM"
$Action= New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "c:\ps\backup_ad.ps1"
Register-ScheduledTask -TaskName "BackupADScript_PS" -Trigger $Trigger -User $User -Action $Action -RunLevel Highest –Force

schedule Active Directory backup script

Thus, we have configured the AD domain controller automatic backup. In the next post, we will look at ways to restore Active Directory from an existing system state backup.

4 comments
10
Facebook Twitter Google + Pinterest
previous post
How to Upgrade Windows Build from an ISO File with Setup.exe CMD
next post
MBR2GPT: Converting MBR to GPT Disk in Windows 10

Related Reading

Configure NTP Time Source for Active Directory Domain

May 6, 2025

How to Cancel Windows Update Pending Restart Loop

May 6, 2025

View Windows Update History with PowerShell (CMD)

April 30, 2025

Cannot Install Network Adapter Drivers on Windows Server

April 29, 2025

Uninstalling Windows Updates via CMD/PowerShell

April 18, 2025

4 comments

Dan June 1, 2020 - 6:17 pm

Brilliant article, just found your site and it’s great!

Reply
Bastiaan September 29, 2020 - 2:30 pm

Thank you!

Reply
chris March 29, 2022 - 12:14 pm

will this work with a linux samba ad

Reply
Alex August 26, 2022 - 3:33 am

Hi there,
Excellent overview of the steps involved. Any particular advandage of using PS in place of the GUI Windows Backup utility to schedule the backups?
Also, has anyone got advice on why would the backup time in repadmin /showbackup * comeup with a recent date even though I am 100% we have not done any scheduled or manual backup in recent months… the network share for the backup is also like half a year behind.
Thank you
Alex

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMware
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • Configuring Proxy Settings on Windows Using Group Policy Preferences
  • Using WMI Filters to Target Group Policies in Active Directory
  • Using Managed Service Accounts (MSA and gMSA) in Active Directory
  • How to Set a User Thumbnail Photo in Active Directory
  • Set Desktop Wallpaper and Logon Screen Background via Group Policy
  • Restoring Active Directory Domain Controller from a Backup
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top