Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • 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 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

June 8, 2023 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

3 comments
7
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

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

How to Query and Change Teams User Presence...

October 8, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

3 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
faig July 26, 2023 - 9:47 am

Not a complete backup. Author didn’t write the restoration steps.

Reply

Leave a Comment Cancel Reply

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

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Fix: Remote Desktop Licensing Mode is not Configured
  • Manage Windows Updates with PSWindowsUpdate PowerShell Module
  • Configuring Port Forwarding in Windows
  • Start Menu or Taskbar Search Not Working in Windows 10/11
  • How to Install Remote Server Administration Tools (RSAT) on Windows
  • How to Delete Old User Profiles in Windows
  • Get-ADUser: Find Active Directory User Info with PowerShell
Footer Logo

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


Back To Top