是否可以安排新数据层 SQL Azure 实例的规模?

Is it possible to schedule a scale of the new data tier SQL Azure Instances?

是否可以安排重新调整 Azure SQL 实例,即在夜间减少到 "Basic",然后在白天增加到 "Standard S2"?

谢谢

编辑

我确实尝试使用 Powershell Runbook 使用 Azure 自动化,但是我收到以下错误:

Error: New-AzureSqlDatabaseServerContext : A network-related or instance-  
specific error occurred while establishing a 
connection to SQL Server. The server was not found or was not accessible.
Verify that the instance name is correct and 
that SQL Server is configured to allow remote connections. (provider: Named 
Pipes Provider, error: 40 - Could not open 
a connection to SQL Server)

我已经提供了所有请求的参数值。也许我有一个复杂的事实,即自动化必须从西欧 运行 而我的资源在北欧?

编辑2

已排序。只需将 DatabaseServerName 指定为名称,并排除“.database.windows.net”。还要确保为 SQL 服务器而不是 Active Directory 创建凭据资产,并使用它。所以再次标记为答案。

你可以做到,但只要确保你有足够的空间来完成扩展。 Scale up 操作似乎是按数据库大小的顺序进行的,而且这是一个没有停机的在线操作。

我通过 运行 CloudService Worker Role 完成了此操作,该角色具有使用更新数据库 Azure 的计划任务 SQL Rest Operation

https://msdn.microsoft.com/en-nz/library/azure/dn505718.aspx

private string GetAuthorizationHeader()
    {
        AuthenticationResult result = null;
        var context = new AuthenticationContext("https://login.windows.net/" + _aadTenantDomain);

        // If you wanted to show a credential dialog, do this: 
        //result = context.AcquireToken( 
        //    "https://management.core.windows.net/", 
        //    _aadClientId, 
        //      new Uri("http://localhost"), PromptBehavior.Auto); 

        // Directly specify the username and password. 
        var credential = new UserCredential(
            "yourusername@address.com",
            "password123");

        result = context.AcquireToken(
            "https://management.core.windows.net/",
            _aadClientId,
                credential);
        if (result == null)
        {
            throw new InvalidOperationException("Failed to obtain the JWT token");
        }

        string token = result.AccessToken;
        return token;
    }


    private void ScaleDatabase(string serverName, string databaseName, string edition, Guid serviceLevelId)
    {

        using (var client = new HttpClient())
        {
            var header = GetAuthorizationHeader();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", header);
            client.DefaultRequestHeaders.Add("x-ms-version", "2012-03-01");

            string url = String.Format("https://management.core.windows.net:8443/{0}/services/sqlservers/servers/{1}/databases/{2}",
                _subscriptionId, serverName, databaseName);

            //string edition = "Standard";
            //string serviceObjId = "f1173c43-91bd-4aaa-973c-54e79e15235b";

            string xmlBody = String.Format(
            "<ServiceResource xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">"
               + "<Name>{0}</Name>"
              + "<Edition>{1}</Edition>"
              + "<ServiceObjectiveId>{2}</ServiceObjectiveId>"
               + "</ServiceResource>", databaseName, edition, serviceLevelId.ToString());

            var request = new HttpRequestMessage(HttpMethod.Put, url);
            request.Content = new StringContent(xmlBody, Encoding.UTF8, "application/xml");

            var response = client.SendAsync(request).Result;
        }

    }

您可能需要添加 nuget 包:Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory

我也发现了这个版本,虽然说是可选的,但实际上是必需的。

此外,如果您要缩小规模,请确保还为所需版本指定了数据库的最大大小。 当前处于标准版且最大数据库大小为 50gb 的数据库将不允许您扩展到基本版,除非您还设置了新的最大数据库大小为 2gb。

您可以使用 Azure Automation 安排作业在浏览器中完成这一切。

Azure 自动化入门:https://azure.microsoft.com/en-us/documentation/articles/automation-create-runbook-from-samples/

这是一个扩展数据库的示例脚本,您可以 运行 作为一项工作:https://gallery.technet.microsoft.com/scriptcenter/Azure-SQL-Database-e957354f