Azure CLI下载Azure Storage Container内的所有文件
在某些场景下,客户需要把Azure Storage的某一个container内的内容都下载到本地。当然采用PowerShell可以定时的进行下载的动作,但有时客户的环境是Linux或MacOS,这时需要采用Azure xplate CLI实现这个功能。本文将介绍如何采用Azure CLI实现这个功能。
安装Azure CLI,可以参考:
http://www.cnblogs.com/hengwei/p/5183493.html
http://www.cnblogs.com/hengwei/p/4781332.html
安装完成后,通过Azure的命令显示Storage Account的信息:
azure storage account list
info: Executing command storage account list
+ Getting storage accounts
data: Name Type Label Location Resource Group
data: ------------------------ ------------ ----- ----------- --------------------------
data: hwtest Standard_LRS China East Default-Storage-ChinaEast
info: storage account list command OK
获得Storage Account的Key:
azure storage account keys list hwtest
info: Executing command storage account keys list
+ Getting storage account keys
data: Primary: pBHrx8d+LDAkyHm2ffljPYygsiSBlbdQh8O45iV12BlFvdjI8kXbqtE17PlpCG0pfTU3yaBQUEEuWuM0tIsobw==
data: Secondary: ss2PunnyTve2sT8R3vaNFJTIcYz0ehmJreKKvmcMSEwSuymbLNqnwDqKznW9Kh03EtZl6fIGAufcT3g+c1UWzw==
info: storage account keys list command OK
先将这个Container的权限设置成Public的模式:
azure storage container set --container hwc -p Container -a hwtest –k pBHrx8d+LDAkyHm2ffljPYygsiSBlbdQh8O45iV12BlFvdjI8kXbqtE17PlpCG0pfTU3yaBQUEEuWuM0tIsobw==
info: Executing command storage container set
+ Set container
+ Getting Storage container information
data: {
data: name: 'hwc',
data: metadata: {},
data: etag: '"0x8D3351F16611905"',
data: lastModified: 'Sun, 14 Feb 2016 09:13:22 GMT',
data: leaseStatus: 'unlocked',
data: leaseState: 'available',
data: requestId: '6f3b08c9-0001-0048-7707-675863000000',
data: publicAccessLevel: 'Container'
data: }
info: storage container set command OK
获得这些信息后,可以通过脚本的方式实现批量文件的下载:
#!/bin/bash container=hwc
btype=block
storageaccount=hwtest
storagekey=pBHrx8d+LDAkyHm2ffljPYygsiSBlbdQh8O45iV12BlFvdjI8kXbqtE17PlpCG0pfTU3yaBQUEEuWuM0tIsobw== files=`azure storage blob list -a $storageaccount -k $storagekey $container |awk '/BlockBlob/ {print $2}'` for file in $files;
do
{
wget https://$storageaccount.blob.core.chinacloudapi.cn/$container/$file
};
done
但这样有一个问题,是需要把整个文件夹变成Public的模式。存在一定的安全隐患。
解决这个问题,可以采用SAS Token的方式实现。
可以通过下面这个脚本进行改进:
#!/bin/bash
container=hwc
btype=block
storageaccount=hwtest
storagekey=pBHrx8d+LDAkyHm2ffljPYygsiSBlbdQh8O45iV12BlFvdjI8kXbqtE17PlpCG0pfTU3yaBQUEEuWuM0tIsobw==
starttime=--
endtime=-- files=`azure storage blob list -a $storageaccount -k $storagekey $container |awk '/BlockBlob/ {print $2}'` for file in $files;
do
{
sastokey=`azure storage blob sas create --container $container --blob $file --permissions rwd --start $starttime --expiry $endtime -a $storageaccount -k $storagekey | awk '/URL/ {print $5}'`
wget $sastokey -O $file
};
done
Azure CLI下载Azure Storage Container内的所有文件的更多相关文章
- 使用 Azure CLI 在 Azure China Cloud 云平台上手动部署一套 Cloud Foundry
这篇文章将介绍如何使用 Azure CLI 在 Azure China Cloud 云平台上手动部署一套 Cloud Foundry.本文的目的在于: 了解作为 PaaS 的 Cloud Foundr ...
- 使用 Azure CLI 管理 Azure 虚拟网络和 Linux 虚拟机
Azure 虚拟机使用 Azure 网络进行内部和外部网络通信. 本教程将指导读者部署两个虚拟机,并为这些 VM 配置 Azure 网络. 本教程中的示例假设 VM 将要托管包含数据库后端的 Web ...
- 使用 Azure CLI 管理 Azure 磁盘
Azure 虚拟机使用磁盘来存储 VM 操作系统.应用程序和数据. 创建 VM 时,请务必选择适用于所需工作负荷的磁盘大小和配置. 本教程介绍如何部署和管理 VM 磁盘. 学习内容: OS 磁盘和临时 ...
- 使用 Azure CLI 2.0 从自定义磁盘创建 Linux VM
本文说明如何在 Azure 中上传自定义的虚拟硬盘 (VHD) 或复制现有 VHD,并从自定义磁盘创建 Linux 虚拟机 (VM). 可以根据要求安装并配置 Linux 分发版,并使用该 VHD 快 ...
- Azure CLI的版本问题
Azure支持多种管理方法.命令行方法有: PowerShell,PowerShell只能运行在Windows上 Azure CLI,而Azure CLI可以运行在Windows.MAC以及Linux ...
- 使用Azure CLI创建Linux虚拟机
Azure提供了三种方式创建虚拟机,分别是Azure CLI.Azure PowerShell和Azure门户.本文介绍使用Azure CLI来创建Linux虚拟机. 使用Azure CLI创建Lin ...
- Linux上使用Azure CLI来管理Azure
在Windows上我们有强大的Powershell提供各种命令来管理Azure的服务,在Linux上微软提供了基于Node.JS的跨平台的Azure Command Line来帮助Linux用户来管理 ...
- [Azure Storage]使用Java上传文件到Storage并生成SAS签名
Azure官网提供了比较详细的文档,您可以参考:https://azure.microsoft.com/en-us/documentation/articles/storage-java-how-to ...
- Azure 基础:Blob Storage
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在前文中介绍了 Table Storage 的基本 ...
随机推荐
- [Oracle]根据字段值全库搜索相关数据表和字段
这个需求比较冷门,但对于在某些特定的情况下,还是会有这样的需要的.好在Oracle实现还比较方便,用存储过程则轻松实现. 查询字符串: create or replace procedure sear ...
- They're much closer in spirit to how our brains work than feedforward networks.
http://neuralnetworksanddeeplearning.com/chap1.html Up to now, we've been discussing neural networks ...
- CSS3中transform,transition和animation的简单介绍和使用方法演示样例
transform是一个属性,本质跟width,height是一样的,加上transform也就是为类添加一个变换属性. transition是一个属性.它是用来控制过渡效果的,由于用transfor ...
- [闲来无事,从头再来][C51篇]导读
目 的: 通过学习C51,熟悉单片机,熟悉C语言,熟悉单片机系统的外部电路. 方 法: 通过看书和使用板子做实验来进行学习 参考资料: <新概念51单片机C语言教程& ...
- 拉普拉斯分布(Laplace distribution)
拉普拉斯分布的定义与基本性质 其分布函数为 分布函数图 其概率密度函数为 密度函数图 拉普拉斯分布与正太分布的比较 从图中可以直观的发现拉普拉斯分布跟正太分布很相似,但是拉普拉斯分布比正太分布有尖的峰 ...
- spring mvc入门教程 转载自【http://elf8848.iteye.com/blog/875830】
目录 一.前言二.spring mvc 核心类与接口三.spring mvc 核心流程图 四.spring mvc DispatcherServlet说明 五.spring mvc 父子上下文的说明 ...
- 人生要golang
第一篇 : 初识golang 第二篇 : 下载及安装 未完待续 ............................................
- Hadoop Pig
Pig包括两部分: 用于描述数据流的语言,称为Pig Latin. 用于执行Pig Latin程序的执行环境,当前有两个环境:单JVM中的本地执行环境和Hadoop集群上的分布式执行环境. Pig内部 ...
- java -ea
两题考的都是 assert和assertionassert是JDK1.4(&+)中新增的关键字,其功能称作assertionassert 条件表达式 如果条件表达式不成立 ...
- Nginix安装教程(Ubuntu)
安装gcc g++的依赖库 #apt-get install build-essential #apt-get install libtool 安装 pcre依赖库 #sudo apt-get u ...