Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Windows Server 2016 / How to Backup and Restore Websites and IIS configuration?

March 15, 2022 PowerShellWindows Server 2016Windows Server 2019

How to Backup and Restore Websites and IIS configuration?

In this article, we’ll look at how to backup websites, application pools, and IIS web server configuration on Windows Server. You can use an Internet Information Services backup to restore a website in the case of a host server failure, or if you migrate/move a website (and/or IIS configuration) to another server.

Contents:
  • Backing Up IIS on Windows Server
  • Restoring an IIS Configuration on a Different Windows Server Host

Backing Up IIS on Windows Server

Backing up the data and configuration of sites running on an Internet Information Service web server consists of several steps:

  1. Backup IIS website files (by default, IIS site files are stored in %SystemDrive%\inetpub\wwwroot ). This folder must be included in the backup plan. It is enough to copy files all files using your backup tool (you can even use the built-in Windows Server Backup -> select the inetpub directory for backup), or simple BAT/PowerShell scripts. For example, to install WSB and back up the inetpub\wwwroot directory to a shared folder, use the following commands:# Install the Windows server feature using PowerShell;
    Install-WindowsFeature -Name Windows-Server-Backup
    # backup IIS website static files
    wbadmin start backup –backupTarget:\\srv-backup1\backup -include:c:\inetpub\wwwroot -vsscopy
  2. Backup (export) current IIS certificates (you can get the list of SSL certificates on the server using this command: netsh http show sslcert ) You can use PowerShell to backup certificates to a shared network folder in the PFX (Personal Information Exchange) format: dir cert:\localmachine\my | Where-Object { $_.hasPrivateKey } | Foreach-Object { [system.IO.file]::WriteAllBytes("\\srv-backup1\backup\$($_.Subject).pfx",($_.Export('PFX', 'secret')) ) } iis ssl certificate bindings, export cert pfx
  3. Backup IIS configuration (settings).

You can backup the IIS configuration using the built-in appcmd tool. Open a command prompt as an administrator  and change directory:

cd c:\Windows\system32\inetsrv

Let’s back up the IIS configuration:

appcmd add backup srv1-iis-backup-2022_03_10

BACKUP object srv1-iis-backup-2022_03_10 added

backup iis configuration using the appcmd tool

Appcmd creates a folder in the c:\Windows\system32\inetsrv\backup directory with the name of your backup. It contains the following files:

  • administration.config
  • applicationHost.config
  • MBSchema.xml
  • MetaBase.xml
  • redirection.config

iis backup folder

It remains to copy this directory to the backup storage device.

On Windows Server 2019/2016, you can use the built-in PowerShell cmdlet to backup IIS instead of appcmd:

Backup-WebConfiguration -Name MyBackup202203

This cmdlet also exports the current IIS settings to $env:Windir\System32\inetsrv\backup.

Restoring an IIS Configuration on a Different Windows Server Host

You can restore your IIS configuration from a backup to the same server or to a different host. Let’s say you need to restore the IIS configuration on a different Windows Server host.

Copy the IIS backup directory to the same folder (c:\windows\system32\backup) on the target server.

To display a list of all available IIS configuration backups, run the command:

appcmd list backup

The copied backup should appear in the list of available ones. Restore the IIS config from a backup:

appcmd restore backup /stop:true srv1-iis-backup-2022_03_10

restore iis config files from a backup with appcmd

The “Restored configuration from backup srv1-iis-backup-2022_03_10 means that the IIS configuration has been successfully restored.

The /stop:true option forces IIS to stop before restoring.

Restore-WebConfiguration -Name srv1-iis-backup-2022_03_10

Note. There are entries like BACKUP “CFGHISTORY_0000000001” in the list of available backups. These are IIS configuration backups created automatically and located in the \inetpub\history directory. Automatic backup features appeared in IIS 7+: the changes to ApplicationHost.config made through IIS Manager are tracked, the 10 latest backups are stored, and the file is checked for changes every 2 minutes.

To delete a previous backup, run the command:

appcmd.exe delete backup BackupName

Note. List of important restrictions and key points:

  • The same IIS version has to be used on both servers. You can check your version of IIS in the registry using PowerShell: get-itemproperty HKLM:\SOFTWARE\Microsoft\InetStp\ | select setupstring,versionstring In my case, this is IIS 10.0 check iis version with powershell
  • If IIS application pools are not run from the built-in accounts, they must be available on the target IIS host.
  • Before restoring IIS, you must import any SSL certificates you use to the new server.

You can also backup your IIS web server using the msdeploy package (Web Deployment Tool). Download and install the msdeploy package on your IIS host and on the target backup host (https://www.microsoft.com/en-us/download/details.aspx?id=43717).

To create an IIS backup (with all sites if multiple sites are running on IIS) to a remote Windows host 192.168.100.112 via webdeploy, the following command can be used:

msdeploy -verb:sync -source:webServer,computername=192.168.100.112 dest:package=c:\Backup\IIS\server1_iis_backup.zip

You can also backup an individual IIS website:

msdeploy –verb:sync -source:contentPath="site_name.com",computername=192.168.100.112 -dest:package=c:\Backup\IIS\site_name.zip

Or copy only static website files from the specified directory:

msdeploy –verb:sync –source:dirPath="c:\inetpub\wwwroot\site_name",computername=192.168.100.112 -dest:package=c:\Backup\IIS\site_name_static_files.zip

2 comments
6
Facebook Twitter Google + Pinterest
previous post
Configuring Central Store for Group Policy ADMX Templates
next post
Managing Hyper-V Virtual Machines with PowerShell

Related Reading

Using PowerShell Behind a Proxy Server

July 1, 2022

Checking Windows Activation Status on Active Directory Computers

June 27, 2022

Configuring Multiple VLAN Interfaces on Windows

June 24, 2022

How to Disable or Enable USB Drives in...

June 24, 2022

Adding Domain Users to the Local Administrators Group...

June 23, 2022

2 comments

Scott Turner February 20, 2017 - 9:26 pm

Thank you for writing this. Depending on user needs for ongoing IIS and SQL Server configuration remediation, rollback, backup and recovery, a commercial solution like Orcaconfig may make sense.

Orca takes configuration inventory snapshots (every few minutes or so) and stores the current configurations of the Production environment. In a recovery or disaster scenario where you lose access to Production and need to fail over to DR, your Production configuration settings already stored automatically.

Reply
Daniel MOUSSORO October 8, 2021 - 11:14 am

Thank you Very much. This tutorial has been very useful to me.

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows 7
  • Windows Server 2019
  • Windows Server 2016
  • Windows Server 2012 R2
  • PowerShell
  • VMWare
  • Hyper-V
  • MS Office

Recent Posts

  • Using PowerShell Behind a Proxy Server

    July 1, 2022
  • How to Access VMFS Datastore from Linux, Windows, or ESXi?

    July 1, 2022
  • How to Deploy Windows 10 (11) with PXE Network Boot?

    June 27, 2022
  • Checking Windows Activation Status on Active Directory Computers

    June 27, 2022
  • Configuring Multiple VLAN Interfaces on Windows

    June 24, 2022
  • How to Disable or Enable USB Drives in Windows using Group Policy?

    June 24, 2022
  • Adding Domain Users to the Local Administrators Group in Windows

    June 23, 2022
  • Viewing a Remote User’s Desktop Session with Shadow Mode in Windows

    June 23, 2022
  • How to Create a Wi-Fi Hotspot on your Windows PC?

    June 23, 2022
  • Configuring SSH Public Key Authentication on Windows

    June 15, 2022

Follow us

woshub.com

ad

  • Facebook
  • Twitter
  • RSS
Popular Posts
  • Installing RSAT Administration Tools on Windows 10 and 11
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • How to Hide Installed Programs in Windows 10 and 11?
  • Manage Windows Updates with PSWindowsUpdate PowerShell Module
  • Tracking and Analyzing Remote Desktop Connection Logs in Windows
  • PowerShell: Get Folder Sizes on Disk in Windows
  • How to Disable or Enable USB Drives in Windows using Group Policy?
Footer Logo

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


Back To Top