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 的基本 ...
随机推荐
- rm_invalid_file
import xlrd import time import sys import os import requests import sqlite3 import threading curPath ...
- 类加载(一):static块 和 Class.forName
1. class Some { static{ System.out.println("1"); } public Some(){ System.out.println(" ...
- c++得到本地username和IP
bool CDlgResetAlarmInfo::GetLocalUserNameAddIP(CString &a_lstrUserName ,CString &a_IpStr) { ...
- STM32L0 HAL库 UART 串口读写功能
串口发送功能: uint8_t TxData[]= "01234abcde"; HAL_UART_Transmit(&huart2,TxData,,0xffff);//把T ...
- 很详细、很移动的Linux makefile 教程
近期在学习Linux下的C编程,买了一本叫<Linux环境下的C编程指南>读到makefile就越看越迷糊,可能是我的理解能不行. 于是google到了以下这篇文章.通俗易懂.然后把它贴出 ...
- jQuery源码分析_工具方法(学习笔记)
expando:生成唯一JQ字符串(内部使用) noConflict():防止冲突 isReady:DOM是否加载完成(内部) readyWait:等待多少文件的计数器(内部) holdReady() ...
- Swift 枚举简单使用
//定义一个枚举 Direction 枚举字符名字 enum Direction{ case North case South case East case West }; enum Directio ...
- Android进程间通信(IPC)机制Binder简要介绍和学习计划【转】
本文转载自:http://blog.csdn.net/luoshengyang/article/details/6618363 在Android系统中,每一个应用程序都是由一些Activity和Ser ...
- mysql 的类型转换函数cast的用法
CAST(expr AS type), CONVERT(expr,type) , CONVERT(expr USING transcoding_name) CAST() ...
- 启动Hive时报错
报错信息如下 Logging initialized -bin/lib/hive-common-.jar!/hive-log4j.properties Exception in thread &quo ...