Azure 服务器每天使用自动化 Runbook 资产进行备份
Azure server Backup daily using automation runbook assets
我想每天为我的 azure 服务器创建一个备份...
因为我正在使用这个 link:
https://gallery.technet.microsoft.com/scriptcenter/Back-up-an-Azure-VM-using-9545f0a1#content
http://blogs.technet.com/b/cbernier/archive/2014/04/08/microsoft-azure-automation.aspx
我创建了一个自动化程序 "knsazureautomation",因为我手动创建了 1 个运行手册 "knsremotepscommand" 并且导入了两个文件:
- Connect-Azure:/scriptcenter/Connect-to-an-Azure-f27a81bb - 下载此脚本
- Connect-AzureVM:/scriptcenter/Connect-to-an-Azure-85f0782c - 下载此脚本
以及 knsremoteps 命令的工作流程(>作者>草稿)
workflow knsremotepscommand
{
Param
(
[parameter(Mandatory=$true)]
[String]
$AzureSubscriptionName,
[parameter(Mandatory=$true)]
[PSCredential]
$AzureOrgIdCredential,
[parameter(Mandatory=$true)]
[String]
$ServiceName,
[parameter(Mandatory=$true)]
[String]
$VMName,
[parameter(Mandatory=$true)]
[String]
$VMCredentialName,
[parameter(Mandatory=$true)]
[String]
$PSCommand
)
# Get credentials to Azure VM
$Credential = Get-AutomationPSCredential -Name $VMCredentialName
if ($Credential -eq $null)
{
throw "Could not retrieve '$VMCredentialName' credential asset. Check that you created this asset in the Automation service."
}
# Set up Azure connection by calling the Connect-Azure runbook. You should call this runbook after
# every CheckPoint-WorkFlow to ensure that the management certificate is available if this runbook
# gets interrupted and starts from the last checkpoint
$Uri = Connect-AzureVM -AzureSubscriptionName $AzureSubscriptionName -AzureOrgIdCredential $AzureOrgIdCredential -ServiceName $ServiceName -VMName $VMName
# Run a command on the Azure VM
$PSCommandResult = InlineScript {
Invoke-command -ConnectionUri $Using:Uri -credential $Using:Credential -ScriptBlock {
Invoke-Expression $Args[0]
} -Args $Using:PSCommand
}
$PSCommandResult
}
创建的资产是
创建自动化:
Account Name: KNSAzureAutomation
Region:EAST US 2
资产:
添加连接
Configure connection
CONNECTION TYPE:azure
NAME: KNSAzureConnection
AUTOMATIONCERTIFICATENAME:KNSAzureCertificationName
SUBSCRIPTIONID: (my azure subscrption id is given)
添加凭据
CREDENTIAL TYPE:WindowsPowerShell Credential
NAME:KNSAzureCredential
添加时间表
Configure Schedule
NAME:KnsAzureBackup1
DESCRIPTION: first backuschedule everaday at 12.45
SELECTED RUNBOOK
KNSremotePScommand
AZUREORGIDCREDENTIAL:vnalluri2006@hotmail.com
AZURESUBSCRIPTIONNAME:BizSpark
PSCOMMAND:ipconfig/all
SERVICENAME:KNSWin
VMCREDENTIALNAME:KNSAzureCredential(Asset Credential name)
VMNAME:knsazurewin1
我收到这个错误:
Credential with name 'vnalluri2006@hotmail.com' not found for account '3c2455db-035a-477c-b20c-51fd74a586fa'.
如果我更改
的凭据
AZUREORGIDCREDENTIAL:vnalluri2006@hotmail.com
至
AZUREORGIDCREDENTIAL:KNSAzureCredential
我收到这个错误:
4/22/2015 4:53:11 PM, Error: Add-AzureAccount : -Credential parameter can only be used with Organization ID credentials. For more information,
please refer to for more information about the difference
between an organizational account and a Microsoft account.
At Connect-AzureVM:24 char:24
+
+ CategoryInfo : CloseError: (:) [Add-AzureAccount], AadAuthenticationFailedException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount
4/22/2015 4:53:12 PM, Error: Select-AzureSubscription : The subscription name BizSpark doesn't exist.
Parameter name: name
At Connect-AzureVM:27 char:27
+
+ CategoryInfo : CloseError: (:) [Select-AzureSubscription], ArgumentException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.SelectAzureSubscriptionCommand
4/22/2015 4:53:17 PM, Error: Get-AzureVM : No default subscription has been designated. Use Select-AzureSubscription -Default <subscriptionName> to
set the default subscription.
At Connect-AzureVM:29 char:29
+
+ CategoryInfo : CloseError: (:) [Get-AzureVM], ApplicationException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureVMCommand
4/22/2015 4:53:17 PM, Error: Get-AzureCertificate : Cannot validate argument on parameter 'Thumbprint'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At Connect-AzureVM:29 char:29
+
+ CategoryInfo : InvalidData: (:) [Get-AzureCertificate], ParameterBindingValidationException
+ FullyQualifiedErrorId :
ParameterArgumentValidationError,Microsoft.WindowsAzure.Commands.ServiceManagement.Certificates.GetAzureCertificate
4/22/2015 4:53:17 PM, Error: Get-AzureWinRMUri : No default subscription has been designated. Use Select-AzureSubscription -Default
<subscriptionName> to set the default subscription.
At Connect-AzureVM:29 char:29
+
+ CategoryInfo : CloseError: (:) [Get-AzureWinRMUri], ApplicationException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureWinRMUri
4/22/2015 4:53:17 PM, Error: Invoke-Command : Cannot validate argument on parameter 'ConnectionUri'. The argument is null, empty, or an element of
the argument collection contains a null value. Supply a collection that does not contain any null values and then try
the command again.
At knsremotepscommand:92 char:92
+
+ CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
我会给你一些建议-
一个。大多数 imp- 转到 ASSET 选项卡并添加适当的 windows powershell 凭据(只需使用用户名和密码,与登录 azure 门户时使用的相同)。
b。在运行手册中添加您的代码。假设您的 powershell 自动化凭证名称是 Backup,您的订阅名称是 xxx。在这种情况下,工作流程将是-
workflow Backup
{
$Cred = Get-AutomationPSCredential -Name
StartVM' Add-AzureAccount -Credential $Cred
Select-AzureSubscription -SubscriptionName “xxx”
inlineScript
{
# YOUR BACK UP CODE HERE
}
}
c。在此之后,您可以根据需要安排您的 Runbook。
希望这篇能帮到你-
http://azure.microsoft.com/blog/2014/11/25/introducing-the-azure-automation-script-converter/ http://azure.microsoft.com/en-us/documentation/articles/automation-create-runbook-from-samples/
谢谢。
如第一个错误所述,您需要使用 Azure AD 凭据从您的 Runbook 向 Azure 进行身份验证,而不是 Microsoft 帐户凭据。有关如何创建 Azure AD OrgID 凭据的更多详细信息,请参阅 http://azure.microsoft.com/blog/2014/08/27/azure-automation-authenticating-to-azure-using-azure-active-directory/。
其他错误都是第一个错误造成的。
我想每天为我的 azure 服务器创建一个备份...
因为我正在使用这个 link:
https://gallery.technet.microsoft.com/scriptcenter/Back-up-an-Azure-VM-using-9545f0a1#content
http://blogs.technet.com/b/cbernier/archive/2014/04/08/microsoft-azure-automation.aspx
我创建了一个自动化程序 "knsazureautomation",因为我手动创建了 1 个运行手册 "knsremotepscommand" 并且导入了两个文件:
- Connect-Azure:/scriptcenter/Connect-to-an-Azure-f27a81bb - 下载此脚本
- Connect-AzureVM:/scriptcenter/Connect-to-an-Azure-85f0782c - 下载此脚本
以及 knsremoteps 命令的工作流程(>作者>草稿)
workflow knsremotepscommand
{
Param
(
[parameter(Mandatory=$true)]
[String]
$AzureSubscriptionName,
[parameter(Mandatory=$true)]
[PSCredential]
$AzureOrgIdCredential,
[parameter(Mandatory=$true)]
[String]
$ServiceName,
[parameter(Mandatory=$true)]
[String]
$VMName,
[parameter(Mandatory=$true)]
[String]
$VMCredentialName,
[parameter(Mandatory=$true)]
[String]
$PSCommand
)
# Get credentials to Azure VM
$Credential = Get-AutomationPSCredential -Name $VMCredentialName
if ($Credential -eq $null)
{
throw "Could not retrieve '$VMCredentialName' credential asset. Check that you created this asset in the Automation service."
}
# Set up Azure connection by calling the Connect-Azure runbook. You should call this runbook after
# every CheckPoint-WorkFlow to ensure that the management certificate is available if this runbook
# gets interrupted and starts from the last checkpoint
$Uri = Connect-AzureVM -AzureSubscriptionName $AzureSubscriptionName -AzureOrgIdCredential $AzureOrgIdCredential -ServiceName $ServiceName -VMName $VMName
# Run a command on the Azure VM
$PSCommandResult = InlineScript {
Invoke-command -ConnectionUri $Using:Uri -credential $Using:Credential -ScriptBlock {
Invoke-Expression $Args[0]
} -Args $Using:PSCommand
}
$PSCommandResult
}
创建的资产是
创建自动化:
Account Name: KNSAzureAutomation Region:EAST US 2
资产:
添加连接
Configure connection CONNECTION TYPE:azure NAME: KNSAzureConnection AUTOMATIONCERTIFICATENAME:KNSAzureCertificationName SUBSCRIPTIONID: (my azure subscrption id is given)
添加凭据
CREDENTIAL TYPE:WindowsPowerShell Credential NAME:KNSAzureCredential
添加时间表
Configure Schedule NAME:KnsAzureBackup1 DESCRIPTION: first backuschedule everaday at 12.45 SELECTED RUNBOOK KNSremotePScommand AZUREORGIDCREDENTIAL:vnalluri2006@hotmail.com AZURESUBSCRIPTIONNAME:BizSpark PSCOMMAND:ipconfig/all SERVICENAME:KNSWin VMCREDENTIALNAME:KNSAzureCredential(Asset Credential name) VMNAME:knsazurewin1
我收到这个错误:
Credential with name 'vnalluri2006@hotmail.com' not found for account '3c2455db-035a-477c-b20c-51fd74a586fa'.
如果我更改
的凭据AZUREORGIDCREDENTIAL:vnalluri2006@hotmail.com
至
AZUREORGIDCREDENTIAL:KNSAzureCredential
我收到这个错误:
4/22/2015 4:53:11 PM, Error: Add-AzureAccount : -Credential parameter can only be used with Organization ID credentials. For more information,
please refer to for more information about the difference
between an organizational account and a Microsoft account.
At Connect-AzureVM:24 char:24
+
+ CategoryInfo : CloseError: (:) [Add-AzureAccount], AadAuthenticationFailedException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount
4/22/2015 4:53:12 PM, Error: Select-AzureSubscription : The subscription name BizSpark doesn't exist.
Parameter name: name
At Connect-AzureVM:27 char:27
+
+ CategoryInfo : CloseError: (:) [Select-AzureSubscription], ArgumentException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.SelectAzureSubscriptionCommand
4/22/2015 4:53:17 PM, Error: Get-AzureVM : No default subscription has been designated. Use Select-AzureSubscription -Default <subscriptionName> to
set the default subscription.
At Connect-AzureVM:29 char:29
+
+ CategoryInfo : CloseError: (:) [Get-AzureVM], ApplicationException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureVMCommand
4/22/2015 4:53:17 PM, Error: Get-AzureCertificate : Cannot validate argument on parameter 'Thumbprint'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At Connect-AzureVM:29 char:29
+
+ CategoryInfo : InvalidData: (:) [Get-AzureCertificate], ParameterBindingValidationException
+ FullyQualifiedErrorId :
ParameterArgumentValidationError,Microsoft.WindowsAzure.Commands.ServiceManagement.Certificates.GetAzureCertificate
4/22/2015 4:53:17 PM, Error: Get-AzureWinRMUri : No default subscription has been designated. Use Select-AzureSubscription -Default
<subscriptionName> to set the default subscription.
At Connect-AzureVM:29 char:29
+
+ CategoryInfo : CloseError: (:) [Get-AzureWinRMUri], ApplicationException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureWinRMUri
4/22/2015 4:53:17 PM, Error: Invoke-Command : Cannot validate argument on parameter 'ConnectionUri'. The argument is null, empty, or an element of
the argument collection contains a null value. Supply a collection that does not contain any null values and then try
the command again.
At knsremotepscommand:92 char:92
+
+ CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
我会给你一些建议-
一个。大多数 imp- 转到 ASSET 选项卡并添加适当的 windows powershell 凭据(只需使用用户名和密码,与登录 azure 门户时使用的相同)。
b。在运行手册中添加您的代码。假设您的 powershell 自动化凭证名称是 Backup,您的订阅名称是 xxx。在这种情况下,工作流程将是-
workflow Backup
{
$Cred = Get-AutomationPSCredential -Name
StartVM' Add-AzureAccount -Credential $Cred
Select-AzureSubscription -SubscriptionName “xxx”
inlineScript
{
# YOUR BACK UP CODE HERE
}
}
c。在此之后,您可以根据需要安排您的 Runbook。
希望这篇能帮到你-
http://azure.microsoft.com/blog/2014/11/25/introducing-the-azure-automation-script-converter/ http://azure.microsoft.com/en-us/documentation/articles/automation-create-runbook-from-samples/
谢谢。
如第一个错误所述,您需要使用 Azure AD 凭据从您的 Runbook 向 Azure 进行身份验证,而不是 Microsoft 帐户凭据。有关如何创建 Azure AD OrgID 凭据的更多详细信息,请参阅 http://azure.microsoft.com/blog/2014/08/27/azure-automation-authenticating-to-azure-using-azure-active-directory/。
其他错误都是第一个错误造成的。