Backup and restore IIS configuration with appcmd
If you are using Windows Server IIS as your web server software, it is important to make regular backups. Luckily, using
appcmd this is quite easy.
Creating backups ensures you have valid data to restore when something went wrong. For example, if you deleted a site that shouldn’t be deleted, you can restore the created IIS backup. It particularly comes in handy when you remove orphaned IIS web applications automatic in a PS script.
Protip: did you know IIS automatically creates these backups when you change settings through IIS Manager? You can find them in
%SystemDrive%\inetpub\history. This is part of the built-in IIS configuration history feature. Neat, right?! :)
appcmd list backup you can view the available IIS configuration history feature:
PS C:\inetpub\history> appcmd list backup BACKUP "CFGHISTORY_0000000104" BACKUP "CFGHISTORY_0000000105" BACKUP "CFGHISTORY_0000000106" BACKUP "CFGHISTORY_0000000107" BACKUP "CFGHISTORY_0000000108" BACKUP "CFGHISTORY_0000000109" BACKUP "CFGHISTORY_0000000110" BACKUP "CFGHISTORY_0000000111" BACKUP "CFGHISTORY_0000000112" BACKUP "CFGHISTORY_0000000113" BACKUP "CFGHISTORY_0000000114"
I can create an IIS backup using the
PS C:\inetpub\history> appcmd add backup BACKUP object "20191105T002034" added
list lists it
PS C:\inetpub\history> appcmd list backup BACKUP "20191105T002034" BACKUP "CFGHISTORY_0000000104" [...]
The backups created with appcmd are saved in the directory
If needed, you can restore a backup easily in IIS with appcmd as well:
PS C:\inetpub\history> appcmd restore backup /backup.name:"20191105T002034" /stop:true Restored configuration from backup "20191105T002034"
The command above restores the backup called “20191105T002034”, and by using
/stop:true I forced IIS to stop before performing the restore.
An easy example is:
PS C:\Users\janreilink> Backup-WebConfiguration -Name MyIISBackup Name Creation Date ---- ------------- MyIISBackup 12/19/2019 12:00:00 AM
Backups are stored in the
My name is Jan. I am not a hacker, coder, developer, programmer or guru. I am merely a system administrator, doing my daily thing at Vevida in the Netherlands. With over 15 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, WordPress, websites & optimization.
Want to support me and donate? Use this link: https://paypal.me/jreilink.