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

时间:2015-07-15 00:46:17

标签: azure azure-sql-database

是否可以安排重命名Azure SQL实例,即减少到" Basic"过夜,然后高档到标准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)

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

EDIT2

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

3 个答案:

答案 0 :(得分:4)

您可以使用Azure自动化安排作业在浏览器中执行此操作。

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

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

答案 1 :(得分:1)

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

答案 2 :(得分:1)

我通过使用使用更新数据库Azure SQL Rest操作的计划任务运行CloudService Worker角色来完成此操作

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。