如何使用Automation Runbook重命名Azure SQL数据库?

时间:2015-03-19 19:24:03

标签: azure azure-automation

我创建了一个Azure SQL DB并将其命名为“TempDb”。我想重命名它。我可以通过自动化Runbook来完成吗?如何?

1 个答案:

答案 0 :(得分:6)

虽然你可以实现这一点,但我真的怀疑通过Automation Runbook这样做的重点是什么?重命名后,第二次尝试运行Runbook时会失败吗?

但无论如何这里是如何:

  1. 创建Azure自动化帐户(如果您尚未
  2. 在Azure Active Directory中创建自动凭据以与Azure自动化一起使用。您可以阅读the great tutorial how to do this here
  3. 使用以下代码创建Runbook:
  4. workflow RenameSqlDb
    {
      $cred = Get-AutomationPSCredential -Name "<youraccount>@<yourdomain>.onmicrosoft.com"
      Add-AzureAccount -Credential $cred
      Select-AzureSubscription "Subscription name for which this account is valid"
      Set-AzureSqlDatabase -ServerName <azure_Sql_server_name> -DatabaseName <TempDB> -NewDatabaseName <NewName_for_theDB>
        Write-Output "Done."
    }
    

    通过参数化ServerNameDatabaseNameNewDatabaseName参数,您可以获得更多创意。

    注意:这是经过测试的工作簿,可以达到预期的效果。