Need to move files from VM and put into storage explorer - Azure

1.3k Views Asked by At

Every day at 8am we have files generated inside a VM that only I can access. I want to get those files automatically uploaded to a storage account that everyone can access, after they have been generated. How is the best way to go about doing this?

1

There are 1 best solutions below

0
On

I have tested in my environment.

You can use PowerShell or bash script to move files from VM to a storage account.

Login to Azure Portal --> Go to your VM --> Under Settings, click on Identity --> Enable System Assigned Identity and click on save

enter image description here

Click on Azure role assignments --> Add Role Assignment --> Select scope as storage --> Select your storage account in the resource --> Select Storage Blob Data Contributor role --> Click on Save

Log in to your VM and install Azcopy : Copy or move data to Azure Storage by using AzCopy v10 | Microsoft Docs

If it is a windows VM, create the below as PowerShell script to copy files from VM to your storage account. If it is a Linux VM, create the below as a bash script :

azcopy login --identity

azcopy copy "path\to\folder\*" "https://StorageAccountName.blob.core.windows.net/ContainerName/"

Create a scheduled task to execute the PowerShell to execute daily at a scheduled time to copy files from VM to your storage account for Windows VM : How To Create a Scheduled Task in Windows 10 (c-sharpcorner.com)

For Linux VM, create a cronjob to run the bash script daily at a scheduled time : How to Create and Run Cron Jobs on Linux - RoseHosting

enter image description here

enter image description here