upload files from URL (FTP server) to Azure storage account - azure

I am trying to download and save large weather forecasts model output into Azure storage account. The data is available from NOAA/NCEP websit ftp://ftp.ncep.noaa.gov/pub/data/nccf/com/hrrr/prod/hrrr.20200220/conus/
Based on the documentation I have read, there are potentially Azcopy, Azure CLI, and Python SDK I can use. I started with Azure CLI, and try to do it with
az storage blob upload
--container-name "hrrr"
--file "ftp://ftp.ncep.noaa.gov/pub/data/nccf/com/hrrr/prod/hrrr.20200220/conus/hrrr.t00z.wrfsfcf36.grib2"
--name "hrrr.t00z.wrfsfcf36.grib"
--account-name "MyStorageAccountName"
--account-key "AccountKey"
Which does not work. I could not find other documentation that is close to what I am trying to do. Any solutions? Ultimately, I am hoping to have a script running automatically that fetch data every hour from the NCEP/NOAA to get download the newest forecast into my Azure storage account.

You can use a fairly simple Logic App to do this. Make it a 'Recurrence' trigger set to the schedule you want.
Actions in Logic App:
FTP - List files in folder
For each file - 'Get file content' then 'Create blob' in storage account.

Related

Failed to copy container from Azure to Local Emulator

scenario
I would like to copy whole contianer from my storage account at Azure to my local storage account at Storage Emulator. I had SAS token to both accounts generated.
I tried in windows 10 CMD:
azcopy copy "https://myazuresrg.blob.core.windows.net/mycontainer/?
sv=2020-08-04&ss=b&srt=co&sp=rltf&se=2021-09-10T15:14:05Z&st=2021-09-
10T07:14:05Z&spr=https&sig=Eb%2FsK9kmwVDJt2PPg2a6wocXkK7EDrj3fgY8uT5dI
IE%3D" "http://127.0.0.1:10000/devstoreaccount1/mycontainer?
sv=2019-07-07&sr=c&sig=XXXXXXXX&se=2021-09-11T07%3A29%3A46Z&sp=rwdl" -
-recursive=true --from-to=BlobLocal
Problem
In logs I can see error:
DOWNLOADFAILED:
https://myazuresrg.blob.core.windows.net/mycontainer/website/footer.js
on?se=2021-09-10t15%3A14%3A05z&sig=-REDACTED-
&sp=rltf&spr=https&srt=co&ss=b&st=2021-09-10t07%3A14%3A05z&sv=2020-08-
04 : 000 : File Creation Error mkdir \\?
\C:\AzCopy\http:\127.0.0.1:10000\devstoreaccount1\mycontainer?sv=2019-
07-07&sr=c&sig=-REDACTED-&se=2021-09-
11T07%3A29%3A46Z&sp=rwdl\mycontainer\website: The filename, directory
name, or volume label syntax is incorrect.
Why Azcopy add prepath \C:\AzCopy to my local acount emulator path?
There are two issues here:
Incorrect use of --from-to. Basically you would use --from-to=BlobLocal when you want to download the blob from storage to your local computer. That's the reason you're seeing azcopy prepending \C:\AzCopy to your local emulator path.
You cannot use azcopy copy to copy blobs from cloud storage account to your storage emulator. Essentially copy blob operation is an async operation where once you initiate the copy operation, Azure Storage service asynchronously copies the blob from source to destination account. For this both source and target account must be in the cloud. Azure Storage service must be able to reach out to both of these accounts. Considering your target account is storage emulator running on your local computer, Azure Storage service will not be able to reach it and thus copy operation will fail.
What you will need to do in this case is first download the blobs from your storage account to your local computer and then upload it in your storage emulator.

Fetch Azure storage dacpac file in ARM Template

Is there a way to get data from Azure Storage like dacpac, zip etc and put in drop folder in CI/CD pipeline?
hm, for saving files to Azure Storage, there is a Azure File Copy task. So you probably have to either use PowerShell (like the Set-AzStorageBlobContent cmdlet) or using the azcopy CLI (you might have to find an image that contains the binary)

How to upload a file from azure blob storage to Linux VM created on azure

I have one large file on my azure blob storage container. I want to move my file from blob storage to Linux VM created on azure> How can I do that using data factory? or any Powershell Command?
The easiest and without any tools is to generate SAS token for the blob and run CURL.
Generate SAS
And then CURL
curl <blob_sas_url> -o output.txt
If you need this automated every time you can generate SAS URL from the script or just use AzCopy.
Please reference this blog:How to copy data to VM from blob storage, it gives you a way to solve the problem with Data Factory:
"To anyone who might get into same problem in future, I solved my problem by using 'copy wizard' present in ADF.
We need to install Data Management Gateway on VM and register it before we use 'copy wizard'.
We need to specify blob storage as source and in destination we need to choose 'File Server Share' option. In 'File Server Share' option we need to specify user credentials which I suppose pipeline uses to login to VM, folder on VM where pipeline will copy the data."
From the Azure Blog Storage document, there is another way can help you Mount Blob storage as a file system with blobfuse on Linux.
Blobfuse is a virtual file system driver for Azure Blob storage. Blobfuse allows you to access your existing block blob data in your storage account through the Linux file system. Blobfuse uses the virtual directory scheme with the forward-slash '/' as a delimiter.
This guide shows you how to use blobfuse, and mount a Blob storage container on Linux and access data. To learn more about blobfuse, read the details in the blobfuse repository.
If you want to use AzCopy, you can reference this document Transfer data with AzCopy and Blob storage. You can download the AzCopy for Linux. It provided the command for upload and download files.
For example, upload file:
azcopy copy "<local-file-path>" "https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-name>/<blob-name>"
For PowerShell, you need to use PowerShell Core 6.x and later on all platforms. It works with Windows and Linux virtual machines using Windows PowerShell 5.1 (Windows only) or PowerShell 6 (Windows and Linux).
You can find the PowerShell commands in this document:Quickstart: Upload, download, and list blobs by using Azure PowerShell
Here is another link talked about Copy Files to Azure VM using PowerShell Remoting 6 (Windows and Linux).
Hope this helps.
You have many options to copy content from the blob store to the disk on the VM:
1. Use AzCopy
2. Use Azure Pipelines - File copy task
3. Use Powershell cmdlets
A lot of content is available on these approaches on SO!
It seems this is not properly documented anywhere so I am sharing the most basic approach which is to use the azcopy tool that is available for both windows/linux OS. This approach doens't need the complexity of creating the credentials/tokens.
Download azcopy
Its simple executable which can be run directly after extraction
Create a managed identity(system-assigned identity) for your Virtual machine. Navigate to VM-> Identity -> Turn the Status to 'ON' -> Save
Now the VM can be assigned permission at the following levels:
Storage account
Container (file system)
Resource group
Subscription
For this case, navigate to storage account -> IAM -> Add role assignment -> Select role 'Storage Blob Data Contributor' -> Assign access to 'Virtual machine' -> Select the desired VM -> SAVE
NOTE: If you give access to the VM on IAM properties of a Resource Group, the VM will be able to access all the storage accounts of the RG.
Login to VM and assume the identity (run the command from the same location where the azcopy is located)
For windows : azcopy login --identity
For linux : ./azcopy login --identity
Upload or download the files now:
azcopy cp "source-file" "storageUri/blob-container/" --recursive=true
Example: azcopy cp "C:\test.txt" "https://mystorageaccount.blob.core.windows.net/backup/" --recursive=true
IAM permission can take few minutes to propagate. If you change/add the permissions/access level anywhere, run the azcopy login --identity command again to get the updated identity.
More info on Azcopy is available here

Upload multiple files in Azure Blob Storage from Linux

Is there a way to upload multiple files to Azure Blob Storage from a Linux machine, either using the terminal or an application (web based or not)?
Thank you for your interest – There are two options to upload files in Azure Blobs from Linux:
Setup and use XPlatCLI by following the steps below:
Install the OS X Installer from http://azure.microsoft.com/en-us/documentation/articles/xplat-cli/
Open a Terminal window and connect to your Azure subscription by either downloading and using a publish settings file or by logging in to Azure using an organizational account (find instructions here)
Create an environment variable AZURE_STORAGE_CONNECTION_STRING and set its value (you will need your account name and account key): “DefaultEndpointsProtocol=https;AccountName=enter_your_account;AccountKey=enter_your_key”
Upload a file into Azure blob storage by using the following command: azure storage blob upload [file] [container] [blob]
Use one of the third party web azure storage explorers like CloudPortam: http://www.cloudportam.com/.
You can find the full list of azure storage explorers here: http://blogs.msdn.com/b/windowsazurestorage/archive/2014/03/11/windows-azure-storage-explorers-2014.aspx.
You can use the find command with the exec option to execute the command to upload each file, as described here as described here:
find *.csv -exec az storage blob upload --file {} --container-name \
CONTAINER_NAME --name {} --connection-string=‘CONNECTION_STRING’ \;
where CONNECTION_STRING is the connection string of your Azure Blob store container, available from portal.azure.com. This will upload all CSV files in your directory to the Azure Blob store associated with the connection string.
If you prefer the commandline and have a recent Python interpreter, the Azure Batch and HPC team has released a code sample with some AzCopy-like functionality on Python called blobxfer. This allows full recursive directory ingress into Azure Storage as well as full container copy back out to local storage. [full disclosure: I'm a contributor for this code]

Task to Deploy Artifact to a container Storage Outside of my account

I am currently creating a CI for the FrontEnd of one of our client.
We need to copy the file coming from our repo the container account of the compagny that manage the operational part (we are only providing the code).
So , the company that will manage the infrastructure has Given us the storage account name (testdeploy) , the container name (artifact-deply) and the key (securekey).
I have managed to connect to the storage via Azure Storage Explorer , but now I need to deploy the artifact on this container via the CI.
The problem is , I don't know how , and I can't find documentation on how to proceed , every doc talk about deploying to a container in the same subscription.
But I do not have acces to this container , I only have it's name and key.
Here is the Yaml to what I have already setup , I do not know if i can help:
steps:
- task: AzureFileCopy#2
displayName: 'AzureBlob File Copy'
inputs:
SourcePath: '$(System.DefaultWorkingDirectory)/_listes-Azure/buildtest'
azureSubscription: 'Paiement à l''utilisation(my_subscription)'
Destination: AzureBlob
storage: testdeploy
ContainerName: 'artifact-deploy/front'
AdditionalArgumentsForBlobCopy: 'securekey'
outputStorageUri: 'https://testdeply.blob.core.windows.net/'
outputStorageContainerSasToken: 'securekey'
Of course when i do this I have this error message :
2019-10-25T10:45:51.1809999Z ##[error]Storage account: fprplistesdeploy not found. The selected service connection 'Service Principal' supports storage accounts of Azure Resource Manager type only.
Since It's not in my subscription scope , it can't acces it.
What I am doing wrong ?
I am using the AzurFileCopy task , is it good?
How can I setup the AzurFileCopy task to a container account that is not on my subscription scope , knowing that the only thing i have is a account name , and a key?
Thanks in advance !
What you basically have to do is to create and use a Shared Access Signature (SAS) to deploy resources into this blob container. Since you have the storage account key you can create a SAS token with Azure Storage Explorer.
Then use Azure Cloud Shell or Azure CLI on local machine for testing purposes. Try to copy a file into the blob container using a SAS token for authorization. If you have problems with authorization using a SAS token you can also test access using Azure Storage Explorer. Such basic tasks are widely known and well documented.
Finally find a way to run the file copy command used while testing in an Azure Pipeline Task. If Azure File Copy task does not fit to your use case, use a more generic task like an Azure CLI task. From reading over the docs it might be that it does not support your use case although the task name indicates that. I see your point. Find out how to access the artifact provided by the build pipeline and copy the file resources into the storage account. If that basically works find out how to improve it. Voila.
So I managed to do it.
Turns out , you can't do it via the AzureFile Copy , this task can't upload to as Container outside your subscription.
You must use an Azur CLI task , here is the script I used:
#!/bin/bash
az storage blob upload --container-name artifact --file $(System.DefaultWorkingDirectory)/artifact_deply/buildtest/front.zip --name front --account-key securekey
I changed all the variable but the idea is here ( I declared the account name in the variable panel of azur devops).
I used the account key , because I had error with the SAS URL , but I think you can easily use the Azur devops variable to pass the SAS Token URL.
And I created a task before this one to zip all the folder , so it's easier to manage.

Resources