#PSTip How to enable Web Deploy automatic backups using PowerShell

Note: This tip requires PowerShell 2.0 or above.

Web Deploy v3 introduced an automatic server-side backup feature for IIS 7 and above. When automatic backups are configured on the server and a user publishes to his site using Web Deploy, it will first take a backup of the live site and store it on the server before committing any changes to the site.

There is no UI to enable this feature. To enable automatic Web Deploy backups, run the following command:

Import-Module WebAdministration
Set-WebConfiguration -PSPath MACHINE/WEBROOT/APPHOST -Filter system.webServer/wdeploy/backup -Value @{turnedOn=$true; enabled=$true}

The default location of backups on the server is set to _“{sitePathParent}{siteName}snapshots”, where “{sitePathParent}” and “{siteName}” are path replacement variables for which are determined at run-time. sitePathParent is the physical file path of the parent of your sites content and siteName is the name of your site. In the case of the “Default Web Site” website, the location will resolve to “C:\inetpub\Default Web Site_snapshots”.

Here’s a sample output of that location. Backups are saved as Zip files:

PS> Get-ChildItem "C:\inetpub\Default Web Site_snapshots" -Name
msdeploy_2014_01_22_10_57_58.zip
msdeploy_2014_01_23_10_27_25.zip
msdeploy_2014_01_28_13_40_26.zip
msdeploy_2014_02_10_18_21_11.zip

By default, only the last 4 backups are stored on the server in the above location. When the maximum number of backups has been created, the oldest backup will be deleted. To change the value, run:

Set-WebConfiguration -PSPath MACHINE/WEBROOT/APPHOST -Filter system.webServer/wdeploy/backup -Value @{numberOfBackups=6}

Note that Web Deploy doesn’t ship with IIS and requires a separate installation.

Share on: