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.
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:
- 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 - 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')) ) }
- 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
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
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
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
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
- 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 - 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
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.
Thank you Very much. This tutorial has been very useful to me.
Not a complete backup. Author didn’t write the restoration steps.