Azure Automation:存储帐户之间blob拷贝
在两个存储帐户之间进行blob拷贝,在客户端,使用Azue PowerShell脚本, 用存储帐户上下文(New-AzureStorageContext)来获取某个StorageAccount中的Container。进而,我们想使用Azure Portal的自动化(Automation), 在Runbook中运行同样的脚本,就出现了如下的错误:
5/25/2015 9:49:19 AM, Error: Get-AzureStorageContainer : Cannot bind parameter 'Context'. Cannot convert the
"Microsoft.WindowsAzure.Commands.Common.Storage.AzureStorageContext" value of type
"Deserialized.Microsoft.WindowsAzure.Commands.Common.Storage.AzureStorageContext" to type
"Microsoft.WindowsAzure.Commands.Common.Storage.AzureStorageContext".
At storageAccountCopy:28 char:28
从网上查询问题原因,有人说是这样的,即Automation中运行的是PowerShell Workflow,其中返回的类型是deserialized, 而在PowerShell中返回的类型是非deserialized,所以你不能将Deserialized类型的AzueStorageContext转换为AzureStorageContext:解决方法是在脚本中使用关键字InlineScript包裹这些代码,使得他们仍然返回AzureStorageContext,而不是PowerShell Workflow中默认的Deserialized AzureStorageContext.
原话如下:
This is due to PowerShell Workflow returning values in deserialized form. See http://social.msdn.microsoft.com/Forums/windowsazure/en-US/1adec597-964c-402e-b1f1-b195d00a20be/exception-calling-azureprovisioningconfig?forum=azureautomation for more details.
The workaround is to just use an InlineScript within the workflow to run these commands in the PowerShell context instead of the PowerShell Workflow context.
示例代码如下:(这段代码所实现的是在同一个Subscription中,将源存储帐户中的blob文件拷贝到目标存储帐户中)
workflow storageAccountCopy
{
#Script by LeX (Qijie Xue)
#sign in Azure Subscription
$Credential = Get-AutomationPSCredential -Name "PSCredential"
$SubscriptionName = Get-AutomationVariable -Name "SubscriptionName" #connect to Azure using PowerShell Credential
Add-AzureAccount -Credential $Credential #Select the Azure subscription to use in this workflow
Select-AzureSubscription -SubscriptionName $SubscriptionName inlinescript{
#source Storage Account
$srcStorageAccountName = ""
$srcStorageKey="" #target Storage Account
$trgStorageAccountName=""
$trgStorageKey ="" # storage context, source and target
$srcContext = New-AzureStorageContext -StorageAccountName $srcStorageAccountName -StorageAccountKey $srcStorageKey
$trgContext = New-AzureStorageContext -StorageAccountName $trgStorageAccountName -StorageAccountKey $trgStorageKey # all containers in source Storage Account
$containers = Get-AzureStorageContainer -Context $srcContext
ForEach($container in $containers)
{
$trgContainers = Get-AzureStorageContainer -Context $trgContext
$exists=0
ForEach($item in $trgContainers)
{
if($item.Name -eq $container.Name)
{
$exists=1
}
}
if($exists -eq 0)
{
New-AzureStorageContainer $container.Name -Permission Container -Context $trgContext
} # do the copy blob for the current container
$blobs = Get-AzureStorageBlob -Container $container.Name -Context $srcContext
$blobs | Start-AzureStorageBlobCopy -DestContainer $container.Name -DestContext $trgContext -Force
}
}
}
Azure Automation:存储帐户之间blob拷贝的更多相关文章
- AzCopy – 跨帐户复制 Blob
您可以随时从 aka.ms/AzCopy 下载最新版本. 去年4月发布的版本中的新增功能 支持跨帐户复制 Blob:AzCopy 允许您在相同存储帐户内或不同存储帐户之间复制 Blob(有关跨帐户 B ...
- C#基础第八天-作业答案-设计类-面向对象方式实现两个帐户之间转账
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- C#基础第八天-作业-设计类-面向对象方式实现两个帐户之间转账
要求1:完成以下两种账户类型的编码.银行的客户分为两大类:储蓄账户(SavingAccount)和信用账户(CreditAccount),两种的账户类型的区别在于:储蓄账户不允许透支,而信用账户可以透 ...
- 掌握 Azure 的注册、帐户和订阅管理 Azure 上云须知
计划使用由世纪互联运营的 Microsoft Azure 的用户,可通过下列流程注册开通并购买所需 Azure 服务:信息获取 > 试用 > 购买 > 账户/订阅管理 > 支付 ...
- Azure AD B2C(二)使用Azure AD B2C为ASP.NET Core 应用设置社交帐户(邮箱)登录/注册
一,引言 上次关于Azure AD B2C 讲到一些概念,有介绍到,Azure AD B2C 也是一种身份验证的解决方案,但是它运行客户使用其首选的社交,企业或者本地账户标识对应用程序和API进行单一 ...
- [转]Azure 表存储和 Windows Azure SQL Database - 比较与对照
本文转自:https://msdn.microsoft.com/library/azure/jj553018 更新时间: 2014年10月 作者:Valery Mizonov 和 Seth Manhe ...
- 初码-Azure系列-存储队列的使用与一个Azure小工具(蓝天助手)
初码Azure系列文章目录 将消息队列技术模型简化,并打造成更适合互联网+与敏捷开发的云服务模式,好像已经是行业趋势,阿里云也在推荐使用消息服务(HTTP协议为主)而来替代消息队列(TCP协议.MQT ...
- 使用 Azure 创建存储和检索文件
本指南将以循序渐进的方式帮助您使用 Azure 将文件存储到云中.我们将逐一介绍如何创建存储账户.创建容器.上传文件.检索文件和删除文件.在本教程中完成的所有操作均符合 1 元试用条件. 本指南将以循 ...
- [Apple开发者帐户帮助]一、开始(2)登录您的开发者帐户
使用Apple ID登录您的开发者帐户.如果您注册了付费程序(Apple Developer Program或Apple Developer Enterprise Program),请使用您用于注册的 ...
随机推荐
- ABAP之DIALOG
明天系统上线,数据一团糟,没人提BUG,无聊ING.... 今天说说SAP开发常用的DIALOG吧 一般单独的DIALOG程序可以直接建成函数组,功能组,普通报表程序. 基本都是统一的样式,主程序中I ...
- 10 vi简介(重点)
1.为什么学习vi? vi很多系统都预装,如果我们的系统没有图像界面,可以使用vi vi是轻量级且执行快速的编辑器 2.vi的几种模式 命令模式.插入模式.底行模式 1) 命令行模式(command ...
- ZOJ 3822(求期望)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- ios基础篇(七)——UISwich、UISlider、UIProgressView的用法总结
一.UISlider UIslider滑块控件在IOS开发中会常用到,可用于调节音量,字体大小等UI方面的交互:UISlider实例提供一个控件,让用户通过左右拖动一个滑块(可称其为“缩略图”)来选择 ...
- [转]Linux下用gcc/g++生成静态库和动态库(Z)
Linux下用gcc/g++生成静态库和动态库(Z) 2012-07-24 16:45:10| 分类: linux | 标签:链接库 linux g++ gcc |举报|字号 订阅 ...
- 一般处理文件.ashx中使用文件session遇到的问题
在给其他网站提供接口的时候用ashx做的,在文件调用cs中的方法,方法中的Session报错:System.NullReferenceException: 未将对象引用设置到对象的实例. /// &l ...
- FFT一周目开坑!
先来一段非递归! #include<bits/stdc++.h> using namespace std; #define N ((1<<18)+3) ); struct ve ...
- LCD驱动 15 -2
1.分配一个fb_info结构体: framebuffer_alloc 2.设置 3.注册 4.硬件相关操 struct fb_fix_screeninfo { char id[16]; /* i ...
- c# 多线程创建 ---简单
Thread t = new Thread(new ParameterizedThreadStart(UploadCard)); t.IsBackground = false;//后台线程 前台线程 ...
- 【转】linux下如何查看某个软件 是否安装?安装路径在哪
以redhat\centos 中php-mysql为例1:如果包是通过yum或者rpm方式安装[root@localhost yum.repos.d]# rpm -qa //找出系统所有的包,找到对应 ...