在 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. 備份可以設定為最多保留一段無限的時間。Backups can be configured to be retained up to an indefinite amount of time. 您可以透過覆寫現有的應用程式或還原到另一個應用程式,將應用程式還原到先前狀態的快照。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

App Service 可以將下列資訊備份到您已設定讓應用程式使用的 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 組態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

  • 若要使用「備份與還原」功能,App Service 方案必須屬於標準層或進階層。The Backup and Restore feature requires the App Service plan to be in the Standard tier or Premium tier. 如需有關調整 App Service 方案以使用更高階層的詳細資訊,請參閱 在 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 儲存體帳戶的詳細資訊,請參閱 Azure 儲存體帳戶概觀For more information on Azure storage accounts, see Azure storage account overview.
  • 備份上限是 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.
  • 不支援備份具 SSL 功能的適用於 MySQL 的 Azure 資料庫。Backups of SSL enabled Azure Database for MySQL is not supported. 如果設定備份,會得到失敗的備份檔案。If a backup is configured, you will get failed backups.
  • 不支援備份具 SSL 功能的適用於 PostgreSQL 的 Azure 資料庫。Backups of SSL enabled Azure Database for PostgreSQL is not supported. 如果設定備份,會得到失敗的備份檔案。If a backup is configured, you will get failed backups.
  • 應用程式內 MySQL 資料庫會自動備份 (不含任何設定)。In-app MySQL databases are automatically backed up without any configuration. 如果您對應用程式內 MySQL 資料庫進行手動設定 (例如,新增連接字串),可能就無法正確備份。If you make manually settings for in-app MySQL databases, such as adding connection strings, the backups may not work correctly.
  • 不支援將具防火牆功能的儲存體帳戶做為備份目的地。Using a firewall enabled storage account as the destination for your backups is not supported. 如果設定備份,會得到失敗的備份檔案。If a backup is configured, you will get failed backups.

建立手動備份Create a manual backup

  1. Azure 入口網站中,瀏覽至您的應用程式頁面,然後選取 [備份]。In the Azure portal, navigate to your app's page, select Backups. [備份] 頁面隨即顯示。The Backups page is displayed.

    Backups page

    注意

    如果您看到下列訊息,必須先按一下該訊息來升級 App Service 方案,才能繼續進行備份。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 accountChoose 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 Database 或 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.

    應用程式內 MySQL 資料庫會自動備份 (不含任何設定)。In-app MySQL databases are automatically backed up without any configuration. 如果您對應用程式內 MySQL 資料庫進行手動設定 (例如,新增連接字串),可能就無法正確備份。If you make manually settings for in-app MySQL databases, such as adding connection strings, the backups may not work correctly.

  6. 在 [備份設定] 頁面中,按一下 [儲存]。In the Backup Configuration page, click Save.

  7. 在 [備份] 頁面中,按一下 [備份]。In the Backups page, click Backup.

    BackUpNow button

    在備份過程中,您會看見進度訊息。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.

    Enable automated backups

設定部分備份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.

注意

備份中的個別資料庫可以是4GB 的上限, 但備份的總大小上限為 10 GBIndividual databases in the backup can be 4GB max but the total max size of the backup is 10GB

從備份中排除檔案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.

使用入口網站時的 Kuku

識別您想要從備份中排除的資料夾。Identify the folders that you want to exclude from your backups. 例如,您想要篩選掉醒目提示的資料夾和檔案。For example, you want to filter out the highlighted folder and files.

Images 資料夾

建立名為 _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:

   \site\wwwroot\Images\brand.png
   \site\wwwroot\Images\2014
   \site\wwwroot\Images\2013

使用 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 Database,請參閱匯入 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.