如何使用 Azure CLI 在 Azure Database for MySQL 中备份和还原服务器How to back up and restore a server in Azure Database for MySQL using the Azure CLI

备注

将要查看的是 Azure Database for MySQL 的新服务。You are viewing the new service of Azure Database for MySQL. 若要查看经典 MySQL Database for Azure 的文档,请访问此页To view the documentation for classic MySQL Database for Azure, please visit this page.

Azure Database for MySQL 服务器定期进行备份以便启用还原功能。Azure Database for MySQL servers are backed up periodically to enable Restore features. 通过此功能,用户可将服务器及其所有数据库还原到新服务器上的某个较早时间点。Using this feature you may restore the server and all its databases to an earlier point-in-time, on a new server.

先决条件Prerequisites

若要完成本操作指南,需要:To complete this how-to guide, you need:

重要

本操作方法指南要求使用 Azure CLI 版本 2.0 或更高版本。This how-to guide requires that you use Azure CLI version 2.0 or later. 若要确认版本,请在 Azure CLI 命令提示符下输入 az --versionTo confirm the version, at the Azure CLI command prompt, enter az --version. 若要安装或升级,请参阅安装 Azure CLITo install or upgrade, see Install Azure CLI.

设置备份配置Set backup configuration

创建服务器时,可以选择将服务器配置为创建本地冗余备份还是创建异地冗余备份。You make the choice between configuring your server for either locally redundant backups or geographically redundant backups at server creation.

备注

创建服务器后,无法在异地冗余或本地冗余之间切换服务器冗余类型。After a server is created, the kind of redundancy it has, geographically redundant vs locally redundant, can't be switched.

通过 az mysql server create 命令创建服务器时,--geo-redundant-backup 参数描述备份冗余选项。While creating a server via the az mysql server create command, the --geo-redundant-backup parameter decides your Backup Redundancy Option. 如果为 Enabled,则创建异地冗余备份。If Enabled, geo redundant backups are taken. 如果为 Disabled,则创建本地冗余备份。Or if Disabled locally redundant backups are taken.

备份保留期由参数 --backup-retention 设置。The backup retention period is set by the parameter --backup-retention.

有关在创建过程中设置这些值的详细信息,请参阅 Azure Database for MySQL 服务器 CLI 快速入门For more information about setting these values during create, see the Azure Database for MySQL server CLI Quickstart.

可以如下所述更改服务器的备份保留期:The backup retention period of a server can be changed as follows:

az mysql server update --name mydemoserver --resource-group myresourcegroup --backup-retention 10

前面的示例将 mydemoserver 的备份保留期更改为 10 天。The preceding example changes the backup retention period of mydemoserver to 10 days.

备份保留期控制可以往回检索多长时间的时间点还原,因为它基于可用备份。The backup retention period governs how far back in time a point-in-time restore can be retrieved, since it's based on backups available. 下一部分中进一步介绍了时间点还原。Point-in-time restore is described further in the next section.

服务器时间点还原Server point-in-time restore

可以将服务器还原到以前的某个时间点。You can restore the server to a previous point in time. 将还原的数据复制到新服务器,并且现有服务器将保持不变。The restored data is copied to a new server, and the existing server is left as is. 例如,如果某个表在今天中午意外删除,可以还原到就在中午之前的时间。For example, if a table is accidentally dropped at noon today, you can restore to the time just before noon. 然后可以从服务器的已还原副本中检索缺少的表和数据。Then, you can retrieve the missing table and data from the restored copy of the server.

若要还原服务器,请使用 Azure CLI az mysql server restore 命令。To restore the server, use the Azure CLI az mysql server restore command.

运行还原命令Run the restore command

若要还原服务器,请在 Azure CLI 命令提示符下输入以下命令:To restore the server, at the Azure CLI command prompt, enter the following command:

az mysql server restore --resource-group myresourcegroup --name mydemoserver-restored --restore-point-in-time 2018-03-13T13:59:00Z --source-server mydemoserver

az mysql server restore 命令需要以下参数:The az mysql server restore command requires the following parameters:

设置Setting 建议的值Suggested value 说明Description  
resource-groupresource-group  myresourcegroupmyresourcegroup  源服务器所在的资源组。The resource group where the source server exists. 
namename mydemoserver-restoredmydemoserver-restored 通过还原命令创建的新服务器的名称。The name of the new server that is created by the restore command.
restore-point-in-timerestore-point-in-time 2018-03-13T13:59:00Z2018-03-13T13:59:00Z 选择要还原到的时间点。Select a point in time to restore to. 此日期和时间必须在源服务器的备份保留期限内。This date and time must be within the source server's backup retention period. 使用 ISO8601 日期和时间格式。Use the ISO8601 date and time format. 例如,可以使用自己的本地时区,如 2018-03-13T05:59:00-08:00For example, you can use your own local time zone, such as 2018-03-13T05:59:00-08:00. 也可以使用 UTC Zulu 格式,如 2018-03-13T13:59:00ZYou can also use the UTC Zulu format, for example, 2018-03-13T13:59:00Z.
source-serversource-server mydemoservermydemoserver 要从其还原的源服务器的名称或 ID。The name or ID of the source server to restore from.

将服务器还原到以前的某个时间点时,会创建新服务器。When you restore a server to an earlier point in time, a new server is created. 原始服务器及其从指定时间点开始创建的数据库会复制到新服务器。The original server and its databases from the specified point in time are copied to the new server.

还原的服务器的位置值和定价层值与原始服务器保持相同。The location and pricing tier values for the restored server remain the same as the original server.

还原过程完成后,找到新服务器,验证数据是否已按预期还原。After the restore process finishes, locate the new server and verify that the data is restored as expected. 新服务器具有在启动还原时对现有服务器有效的相同服务器管理员登录名和密码。The new server has the same server admin login name and password that was valid for the existing server at the time the restore was initiated. 可以从新服务器的“概述” 页更改密码。The password can be changed from the new server's Overview page.

此外,还原操作完成后,有两个服务器参数将在还原操作后重置为默认值(而不是从主服务器复制)Additionally, after the restore operation finishes, there are two server parameters which are reset to default values (and are not copied over from the primary server) after the restore operation

  • time_zone - 此值设置为默认值“SYSTEM”time_zone - This value to set to DEFAULT value SYSTEM
  • event_scheduler - 还原服务器上的 event_scheduler 设置为“OFF”event_scheduler - The event_scheduler is set to OFF on the restored server

你将需要从主服务器复制该值,然后通过重新配置服务器参数在还原服务器上对其进行设置You will need to copy over the value from teh primary server and set it on the restored server by reconfiguring the server parameter

在还原期间创建的新服务器没有原始服务器上存在的 VNet 服务终结点。The new server created during a restore does not have the VNet service endpoints that existed on the original server. 需要为此新服务器单独设置这些规则。These rules need to be set up separately for this new server. 将从原始服务器还原防火墙规则。Firewall rules from the original server are restored.

异地还原Geo restore

如果为服务器配置了异地冗余备份,则可以从该现有服务器的备份创建新服务器。If you configured your server for geographically redundant backups, a new server can be created from the backup of that existing server. 可以在 Azure Database for MySQL 可用的任何区域中创建此新服务器。This new server can be created in any region that Azure Database for MySQL is available.

若要使用异地冗余备份创建服务器,请使用 Azure CLI az mysql server georestore 命令。To create a server using a geo redundant backup, use the Azure CLI az mysql server georestore command.

备注

首次创建服务器时,该服务器可能不会立即可用于异地还原。When a server is first created it may not be immediately available for geo restore. 填充必需的元数据可能需要几个小时。It may take a few hours for the necessary metadata to be populated.

若要异地还原服务器,请在 Azure CLI 命令提示符下输入以下命令:To geo restore the server, at the Azure CLI command prompt, enter the following command:

az mysql server georestore --resource-group myresourcegroup --name mydemoserver-georestored --source-server mydemoserver --location chinaeast2 --sku-name GP_Gen5_8 

此命令在“中国东部 2”中创建一个名为 mydemoserver-georestored 且将属于 myresourcegroup 的新服务器。This command creates a new server called mydemoserver-georestored in China East 2 that will belong to myresourcegroup. 它是第 5 代常规用途服务器,具有 8 个 vCore。It is a General Purpose, Gen 5 server with 8 vCores. 该服务器是基于也在资源组 myresourcegroup 中的 mydemoserver 的异地冗余备份创建的。The server is created from the geo-redundant backup of mydemoserver, which is also in the resource group myresourcegroup

如果希望在与现有服务器不同的资源组中创建新服务器,则需要如下例所示在 --source-server 参数中限定服务器名称:If you want to create the new server in a different resource group from the existing server, then in the --source-server parameter you would qualify the server name as in the following example:

az mysql server georestore --resource-group newresourcegroup --name mydemoserver-georestored --source-server "/subscriptions/$<subscription ID>/resourceGroups/$<resource group ID>/providers/Microsoft.DBforMySQL/servers/mydemoserver" --location chinaeast2 --sku-name GP_Gen5_8

az mysql server georestore 命令需要以下参数:The az mysql server georestore command requires the following parameters:

设置Setting 建议的值Suggested value 说明Description  
resource-groupresource-group myresourcegroupmyresourcegroup 新服务器将属于的资源组的名称。The name of the resource group the new server will belong to.
namename mydemoserver-georestoredmydemoserver-georestored 新服务器的名称。The name of the new server.
source-serversource-server mydemoservermydemoserver 将使用其异地冗余备份的现有服务器的名称。The name of the existing server whose geo redundant backups are used.
locationlocation chinaeast2chinaeast2 新服务器的位置。The location of the new server.
sku-namesku-name GP_Gen5_8GP_Gen5_8 此参数设置新服务器的定价层、计算层代和 vCore 数。This parameter sets the pricing tier, compute generation, and number of vCores of the new server. GP_Gen5_8 映射为一个第 5 代常规用途服务器,具有 8 个 vCore。GP_Gen5_8 maps to a General Purpose, Gen 5 server with 8 vCores.

通过异地还原创建新服务器时,它将继承与源服务器相同的存储大小和定价层。When creating a new server by a geo restore, it inherits the same storage size and pricing tier as the source server. 在创建过程中无法更改这些值。These values cannot be changed during creation. 创建新服务器后,可以纵向扩展其存储大小。After the new server is created, its storage size can be scaled up.

还原过程完成后,找到新服务器,验证数据是否已按预期还原。After the restore process finishes, locate the new server and verify that the data is restored as expected. 新服务器具有在启动还原时对现有服务器有效的相同服务器管理员登录名和密码。The new server has the same server admin login name and password that was valid for the existing server at the time the restore was initiated. 可以从新服务器的“概述” 页更改密码。The password can be changed from the new server's Overview page.

在还原期间创建的新服务器没有原始服务器上存在的 VNet 服务终结点。The new server created during a restore does not have the VNet service endpoints that existed on the original server. 需要为此新服务器单独设置这些规则。These rules need to be set up separately for this new server. 将从原始服务器还原防火墙规则。Firewall rules from the original server are restored.

后续步骤Next steps