您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

在 Azure 中备份应用Back up your app in Azure

利用 Azure App Service 中的备份和还原功能,可以轻松地手动或按计划创建应用备份。The Backup and Restore feature in Azure App Service lets you easily create app backups manually or on a schedule. 通过覆盖现有应用或还原为另一应用可将应用还原为先前状态的快照。You can restore the app to a snapshot of a previous state by overwriting the existing app or restoring to another app.

有关从备份中还原应用的信息,请参阅在 Azure 中还原应用For information on restoring an app from backup, see Restore an app in Azure.

备份的内容What gets backed up

应用服务可将以下信息备份到你配置应用使用的 Azure 存储帐户和容器。App Service can back up the following information to an Azure storage account and container that you have configured your app to use.

  • 应用配置App configuration
  • 文件内容File content
  • 连接到应用的数据库Database connected to your app

备份功能支持以下数据库解决方案:The following database solutions are supported with backup feature:


每个备份都是应用的完整脱机副本,而不是增量更新。Each backup is a complete offline copy of your app, not an incremental update.

要求和限制Requirements and restrictions

  • 备份和还原功能要求应用服务计划处于标准层或高级层。The Backup and Restore feature requires the App Service plan to be in the Standard tier or Premium tier. 有关缩放应用服务计划以使用更高层的详细信息,请参阅增加 Azure 中的应用For more information about scaling your App Service plan to use a higher tier, see Scale up an app in Azure.
    与标准层相比,高级层每日允许更多备份量。Premium tier allows a greater number of daily back ups than Standard tier.
  • 在与要备份的应用相同的订阅中,需要有一个 Azure 存储帐户和容器。You need an Azure storage account and container in the same subscription as the app that you want to back up. 有关 Azure 存储帐户的详细信息,请参阅本文结尾处的链接For more information on Azure storage accounts, see the links at the end of this article.
  • 最多可备份 10 GB 的应用和数据库内容。Backups can be up to 10 GB of app and database content. 如果备份大小超过此限制,会出错。If the backup size exceeds this limit, you get an error.

创建手动备份Create a manual backup

  1. Azure 门户中,导航到应用的页面,然后选择“备份”。In the Azure portal, navigate to your app's page, select Backups. 将显示“备份”页。The Backups page is displayed.



    若显示以下消息,请单击该消息升级 应用服务计划,才能继续备份。If you see the following message, click it to upgrade your App Service plan before you can proceed with backups. 有关详细信息,请参阅增加 Azure 中的应用For more information, see Scale up an app in Azure.
    选择存储帐户Choose storage account

  2. 在“备份”页中,单击“配置” 单击“配置”In the Backup page, Click Configure Click Configure

  3. 在“备份配置”页中,单击“存储: 未配置”来配置存储帐户。In the Backup Configuration page, click Storage: Not configured to configure a storage account.


  4. 选择“存储帐户”和“容器”来选择备份目标。Choose your backup destination by selecting a Storage Account and Container. 该存储帐户必须与要备份的应用属于同一订阅。The storage account must belong to the same subscription as the app you want to back up. 也可在各自的页面中新建存储帐户或容器。If you wish, you can create a new storage account or a new container in the respective pages. 完成后,单击“选择”。When you're done, click Select.


  5. 在仍处于打开状态的“备份配置”页中,可配置“备份数据库”,然后选择备份要包含的数据库(SQL 数据库或 MySQL),然后单击“确定”。In the Backup Configuration page that is still left open, you can configure Backup Database, then select the databases you want to include in the backups (SQL database or MySQL), then click OK.



    若要使数据库显示在此列表中,其连接字符串必须位于应用中“应用程序设置”页的“连接字符串”部分中。For a database to appear in this list, its connection string must exist in the Connection strings section of the Application settings page for your app.

  6. 在“备份配置”页中,单击“保存”。In the Backup Configuration page, click Save.
  7. 在“备份”页中,单击“备份”。In the Backups page, click Backup.

    BackUpNow 按钮

    备份过程中会显示进度消息。You see a progress message during the backup process.

配置存储帐户和容器后,可随时启动手动备份。Once the storage account and container is configured, you can initiate a manual backup at any time.

配置自动执行的备份Configure automated backups

  1. 在“备份配置”页中,将“计划备份”设置为“开”。In the Backup Configuration page, set Scheduled backup to On.


  2. 此时将显示备份计划选项,将“计划备份”设置为“开”,然后按需配置备份计划,并单击“确定”。Backup schedule options will show up, set Scheduled Backup to On, then configure the backup schedule as desired and click OK.


配置部分备份Configure Partial Backups

有时你不想备份应用中的所有内容。Sometimes you don't want to back up everything on your app. 以下是一些示例:Here are a few examples:

  • 设置每周备份应用,其中包含永远不会更改的静态内容,例如旧的博客文章或图像。You set up weekly backups of your app that contains static content that never changes, such as old blog posts or images.
  • 应用的内容超过 10 GB(这是一次可以备份的最大量)。Your app has over 10 GB of content (that's the max amount you can back up at a time).
  • 不想备份日志文件。You don't want to back up the log files.

使用部分备份可以精确选择需要备份的文件。Partial backups allow you choose exactly which files you want to back up.

从备份中排除文件Exclude files from your backup

假定应用中包含的日志文件和静态映像已经过备份且不会发生更改。Suppose you have an app that contains log files and static images that have been backup once and are not going to change. 这种情况下,可排除这些文件夹和文件,以免其存储在将来的备份中。In such cases, you can exclude those folders and files from being stored in your future backups. 若要从备份中排除文件和文件夹,请在应用的 D:\home\site\wwwroot 文件夹中创建一个 _backup.filter 文件。To exclude files and folders from your backups, create a _backup.filter file in the D:\home\site\wwwroot folder of your app. 指定要在此文件中排除的文件和文件夹列表。Specify the list of files and folders you want to exclude in this file.

访问文件的一种简单方式是使用 Kudu。An easy way to access your files is to use Kudu. 单击 Web 应用的“高级工具”->“转到”设置,访问 Kudu。Click Advanced Tools -> Go setting for your web app to access Kudu.

使用门户的 Kudu

确定要从备份中排除的文件夹。Identify the folders that you want to exclude from your backups. 例如,筛选出突出显示的文件夹和文件。For example, you want to filter out the highlighted folder and files.


创建名为 _backup.filter 的文件并将上述列表放在文件中,但删除 D:\homeCreate a file called _backup.filter and put the preceding list in the file, but remove D:\home. 每行列出一个目录或文件。List one directory or file per line. 文件的内容应为:So the content of the file should be:


使用 ftp 或任何其他方法,将 _backup.filter 文件上传到站点的 D:\home\site\wwwroot\ 目录。Upload _backup.filter file to the D:\home\site\wwwroot\ directory of your site using ftp or any other method. 如果需要,可使用 Kudu DebugConsole 直接创建此文件,并在其中插入内容。If you wish, you can create the file directly using Kudu DebugConsole and insert the content there.

采用通常使用的相同方式运行备份,即手动自动Run backups the same way you would normally do it, manually or automatically. 现在,_backup.filter 中指定的任何文件和文件夹已从计划启动或手动启动的将来备份中排除。Now, any files and folders that are specified in _backup.filter is excluded from the future backups scheduled or manually initiated.


采用与还原定期备份相同的方式,还原站点的部分备份。You restore partial backups of your site the same way you would restore a regular backup. 还原过程会执行正确的操作。The restore process does the right thing.

还原完整备份后,站点上的所有内容都被替换为备份中的任何内容。When a full backup is restored, all content on the site is replaced with whatever is in the backup. 如果文件在站点上但不在备份中,则会将其删除。If a file is on the site, but not in the backup it gets deleted. 但是,还原部分备份时,位于其中一个方块列表目录或任何方块列表文件中的任何内容都保持不变。But when a partial backup is restored, any content that is located in one of the blacklisted directories, or any blacklisted file, is left as is.

如何存储备份How backups are stored

对应用进行了一次或多次备份后,可在存储帐户的“容器”页中看到备份以及应用。After you have made one or more backups for your app, the backups are visible on the Containers page of your storage account, and your app. 在存储帐户中,每个备份都由一个 .zip 文件和一个 .xml 文件组成,前者包含备份数据,后者包含 .zip 文件内容的清单。In the storage account, each backup consists of a.zip file that contains the backup data and an .xml file that contains a manifest of the .zip file contents. 如果想要在无需实际执行应用还原的情况下访问备份,则可以解压缩并浏览这些文件。You can unzip and browse these files if you want to access your backups without actually performing an app restore.

应用的数据库备份存储在 .zip 文件的根目录中。The database backup for the app is stored in the root of the .zip file. 对于 SQL 数据库,这是 BACPAC 文件(无文件扩展名),并且可以导入。For a SQL database, this is a BACPAC file (no file extension) and can be imported. 若要基于 BACPAC 导出创建 SQL 数据库,请参阅导入 BACPAC 文件以创建新的用户数据库To create a SQL database based on the BACPAC export, see Import a BACPAC File to Create a New User Database.


改动 websitebackups 容器中的任何文件都导致备份无效,进而无法还原。Altering any of the files in your websitebackups container can cause the backup to become invalid and therefore non-restorable.

使用脚本自动化Automate with scripts

可以在 Azure CLIAzure PowerShell 中使用脚本自动备份管理。You can automate backup management with scripts, using the Azure CLI or Azure PowerShell.

相关示例如下所示:For samples, see:

后续步骤Next Steps

有关从备份中还原应用的信息,请参阅在 Azure 中还原应用For information on restoring an app from a backup, see Restore an app in Azure.