使用 Azure CLI 还原 Azure Database for MariaDB 服务器Restore an Azure Database for MariaDB server using Azure CLI

此示例 CLI 脚本可将单个 Azure Database for MariaDB 服务器还原到前一个时间点。This sample CLI script restores a single Azure Database for MariaDB server to a previous point in time.

如果没有 Azure 试用版订阅,请在开始前创建一个试用版订阅If you don't have an Azure trail subscription, create a trial subscription before you begin.

先决条件Prerequisites

  • 如果需要,请安装 Azure CLI 来运行 CLI 参考命令。If you prefer, install the Azure CLI to run CLI reference commands.

    • 如果使用的是本地安装,请使用 az login 命令登录到 Azure CLI。If you're using a local installation, sign in to the Azure CLI by using the az login command. 若要完成身份验证过程,请遵循终端中显示的步骤。To finish the authentication process, follow the steps displayed in your terminal. 有关其他登录选项,请参阅登录 Azure CLIFor additional sign-in options, see Sign in with the Azure CLI.

    • 出现提示时,请在首次使用时安装 Azure CLI 扩展。When you're prompted, install Azure CLI extensions on first use. 有关扩展详细信息,请参阅使用 Azure CLI 的扩展For more information about extensions, see Use extensions with the Azure CLI.

    • 运行 az version 以查找安装的版本和依赖库。Run az version to find the version and dependent libraries that are installed. 若要升级到最新版本,请运行 az upgradeTo upgrade to the latest version, run az upgrade.

  • 本文需要 Azure CLI 版本 2.0 或更高版本。This article requires version 2.0 or later of the Azure CLI.

示例脚本Sample script

在此示例脚本中,编辑突出显示的行,将管理员用户名和密码更新为你自己的。In this sample script, edit the highlighted lines to update the admin username and password to your own. az monitor 命令中使用的订阅 ID 替换为自己的订阅 ID。Replace the subscription ID used in the az monitor commands with your own subscription ID.

#!/bin/bash

# Create a resource group
az group create \
--name myresourcegroup \
--location chinaeast2

# Create a MariaDB server in the resource group
# Name of a server maps to DNS name and is thus required to be globally unique in Azure.
# Substitute the <server_admin_password> with your own value.
az mariadb server create \
--name mydemoserver \
--resource-group myresourcegroup \
--location chinaeast2 \
--admin-user myadmin \
--admin-password <server_admin_password> \
--sku-name GP_Gen5_2 \

# Restore a server from backup to a new server
az mariadb server restore \
--name mydemoserver-restored \
--resource-group myresourcegroup \
--restore-point-in-time "2018-02-11T13:10:00Z" \
--source-server mydemoserver

清理部署Clean up deployment

运行脚本示例后,请使用以下命令删除资源组以及与其关联的所有资源。Use the following command to remove the resource group and all resources associated with it after the script has been run.

#!/bin/bash
az group delete --name myresourcegroup

脚本说明Script explanation

此脚本使用下表中列出的命令:This script uses the commands outlined in the following table:

命令Command 说明Notes
az group createaz group create 创建用于存储所有资源的资源组。Creates a resource group in which all resources are stored.
az mariadb server createaz mariadb server create 创建用于托管数据库的 MariaDB 服务器。Creates a MariaDB server that hosts the databases.
az mariadb server restoreaz mariadb server restore 从备份还原服务器。Restore a server from backup.
az group deleteaz group delete 删除资源组,包括所有嵌套的资源。Deletes a resource group including all nested resources.

后续步骤Next steps