1
votes

I'm using Azure Data Lake Gen2 and I have a folder named myfolder with 1000s of files. Is there a command on the Azure Storage CLI for renaming the folder and/or move the entire folder to another location of the ADLS Gen2?

Inside Azure Databricks I can easily leverage the linux mv bash command:

  • mv myfolder newname for renaming myfolder
  • mv myfolder /dbfs/mount/myadls/target/ for moving myfolder to a target folder.

Is there a simple way of doing the same with the Azure CLI?

2

2 Answers

0
votes

According to my research, if you want to manage Data Lake Gen2 directories, now we just can use Azure data lake gen2 rest api. For more details, please refer to the document.

For example, if you want to rename your folder, you can use the rest api

PuT https://<your account name>.dfs.core.windows.net/<file system name>/<new folder name>
Header:
x-ms-rename-source : /<file system name>/<orginal folder name>
Authorization : Bearer access token.

Regarding how to call the rest apiļ¼Œ please refer to the following steps 1. Create a service principal

az login
az ad sp create-for-rbac --name ServicePrincipalName
  1. assign role to the service principal
az role assignment create \
    --role "Storage Blob Data Contributor" \
    --assignee < your service principal name> \
    --scope "/subscriptions/<subscription>/resourceGroups/<resource-group>/providers/Microsoft.Storage/storageAccounts/<storage-account>"
  1. Call the rest api
az login --service-principal  --username <your service principal app id> --password <your service principal password>--tenant <your tenant id>

az rest --method put --uri https://testadls05.dfs.core.windows.net/test/testFolder --resource https://storage.azure.com --headers x-ms-rename-source=/test/testFolder1

enter image description here enter image description here

0
votes

UPDATE: An ADLS Gen2 CLI is now available

We can rename or move a directory by using the az storage fs directory move command.

Example 1: Renaming a directory from the name my-directory to the name my-new-directory in the same file system:

az storage fs directory move -n my-directory -f my-file-system --new-directory "my-file-system/my-new-directory" --account-name mystorageaccount --auth-mode login

Example 2: This example moves a directory to a file system named my-second-file-system.

az storage fs directory move -n my-directory -f my-file-system --new-directory "my-second-file-system/my

For more info, here's the official documentation.