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 的基本 ...
随机推荐
- Zookeeper Curator 事件监听 - 秒懂
目录 写在前面 1.1. Curator 事件监听 1.1.1. Watcher 标准的事件处理器 1.1.2. NodeCache 节点缓存的监听 1.1.3. PathChildrenCache ...
- Linux中源码包安装
1.准备环境 a.因为是编译安装,所以需要安装gcc编译器 b.下载源码包 2.注意事项 a.源代码保存位置 /usr/local/src/ b.软件安装位置 /usr/local/ c.如何确定安装 ...
- The path "fos_user.from_email.address" cannot contain an empty value, but got null.
The path "fos_user.from_email.address" cannot contain an empty value, but got null.. 修改 pa ...
- Example 1 - XY plots
http://www.ncl.ucar.edu/Document/Manuals/Getting_Started/Examples/gsun01n.shtml Frame 1 Frame 2 Fram ...
- C#判断VS是否处于设计模式
public class CheckDesingModel { public static bool IsDesingMode() { bool ReturnFlag = false; if (Lic ...
- python中自定义排序函数
Python内置的 sorted()函数可对list进行排序: >>>sorted([36, 5, 12, 9, 21]) [5, 9, 12, 21, 36] 但 sorted() ...
- PHP操作MySQL事务处理
PHP操作MySQL事务处理 /*************** 用begin,rollback,commit来实现 ***************/ /*方法二*/ $conn = mysqli_co ...
- 第三篇、javascript整数和字符串
一.整数 JavaScript中不区分整数值和浮点数值,JavaScript中所有数字均用浮点数值表示. 转换: parseInt(..) 将某值转换成数字,不成功则NaN parseFloat ...
- php中删除数组的第一个元素和最后一个元素的函数
对于一个php数组,该如何删除该数组的第一个元素或者最后一个元素呢?其实这两个过程都可以通过php自带的函数 array_pop 和 array_shift 来完成,下面就具体介绍一下如何来操作. ( ...
- 算法(Algorithms)第4版 练习 1.3.41
方法实现: //1.3.41 public Queue(Queue<Item> q) { Queue<Item> result = new Queue<Item>( ...