Web 部署自動備份

Web 部署提供了在部署時自動備份目標 Web 站點(而不是目標 Web 應用程式!)的選項。建議允許 Web 應用程式回滾。

要配置自動備份,必須遵循以下步驟:

1)啟用備份

在 Powershell 中開啟%programfiles%\IIS\Microsoft Web Deploy V3\scripts\BackupScripts.ps1

執行以下命令:

# 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)檢查全域性或站點級別的備份設定

Get-BackupSettings
Get-BackupSettings -SiteName "Default Web Site"

3)進一步的備份定製

可以為每個網站配置備份設定。開啟 applicationHost.config 併為其特定位置新增備份設定:

<location path="siteName">
    <system.webServer>
        <wdeploy>
            <backup enabled="true" numberOfBackups="4">
                <excludedProviders>
                    <clear />
                    <provider name="dbfullsql" />
                </excludedProviders>
            </backup>
        </wdeploy>
    </system.webServer>
</location>

有關與命令列使用相關的安全相關資訊和其他資訊,請訪問本文