Web deployment offers the option to automatically backup target Web site (not target Web application!) on deployment. This is recommended to allow web application rollback.
In order to configure automatic backups, the following steps must be followed:
1) Enable backups
Open %programfiles%\IIS\Microsoft Web Deploy V3\scripts\BackupScripts.ps1
in Powershell
Execute the following commands:
# Turns on all backup functionality
TurnOn-Backups -On $true
# Turns off all backup functionality
TurnOn-Backups -On $false
# Changes default global backup behavior to enabled
Configure-Backups -Enabled $true
# Changes default backup behavior for site "foo" to enabled
Configure-Backups -SiteName "foo" -Enabled $true
# Changes the path of where backups are stored to a sibling directory named "siteName_snapshots".
# For more information about path variables, see the "backupPath" attribute in the section
# "Configuring Backup Settings on the Server for Global usage manually in IIS Config"
Configure-Backups -BackupPath "{SitePathParent}\{siteName}_snapshots"
# Configures default backup limit to 5 backups
Configure-Backups -NumberOfBackups 5
# Configures sync behavior to fail if a sync fails for any reason
Configure-Backups -ContinueSyncOnBackupFailure $false
# Adds providers to skip when performing a backup
Configure-Backups -AddExcludedProviders @("dbmysql","dbfullsql")
# Allows a site administrator to enable backups and set the number of backups at the site level
Configure-BackupSettingsProvider -CanSetEnabled $true -CanSetNumBackups $true
# Allows a site administrator to control which providers they want to skip in a backup, as
# well as whether they can continue a sync after a backup failure
Configure-BackupSettingsProvider -CanSetContinueSyncOnBackupFailure $true -CanAddExcludedProviders $true
2) Check backup settings on global or site level
Get-BackupSettings
Get-BackupSettings -SiteName "Default Web Site"
3) Further backup customization
Backup settings can be configured for each web site. Open applicationHost.config
and add backup settings for its specific location:
<location path="siteName">
<system.webServer>
<wdeploy>
<backup enabled="true" numberOfBackups="4">
<excludedProviders>
<clear />
<provider name="dbfullsql" />
</excludedProviders>
</backup>
</wdeploy>
</system.webServer>
</location>
For security related information and other information related to command line usage, access this article.