Azure Storage Management CLI Commands
This section provides a comprehensive reference for the Azure CLI commands used to manage Azure Storage resources. You can leverage these commands for automating storage operations, scripting deployments, and integrating with other services.
Getting Started with Azure CLI for Storage
Before you begin, ensure you have the Azure CLI installed. You can download it from Microsoft Docs. Once installed, log in to your Azure account using:
az login
Core Storage Command Group: az storage
The primary command group for interacting with Azure Storage is az storage. This group is further divided into subgroups for different storage services like Blob, File, Queue, and Table.
Blob Storage Management
Manage blobs, containers, and their properties.
Key Commands:
az storage blob upload: Upload a blob.az storage blob download: Download a blob.az storage blob list: List blobs in a container.az storage container create: Create a new container.az storage container delete: Delete a container.az storage container policy create: Create a shared access policy.
Example: Uploading a blob
az storage blob upload \
--account-name mystorageaccount \
--container-name mycontainer \
--name myblob.txt \
--file /path/to/local/myblob.txt \
--account-key YOUR_ACCOUNT_KEY
File Storage Management
Manage Azure Files shares, directories, and files.
Key Commands:
az storage share create: Create a file share.az storage share list: List file shares.az storage directory create: Create a directory in a share.az storage file upload: Upload a file to a share.az storage file download: Download a file from a share.
Example: Creating a file share
az storage share create \
--account-name mystorageaccount \
--name myfileshare \
--quota 5120 \
--account-key YOUR_ACCOUNT_KEY
Queue Storage Management
Manage Azure Queues for message queuing.
Key Commands:
az storage message put: Add a message to a queue.az storage message get: Retrieve messages from a queue.az storage message clear: Clear all messages from a queue.az storage queue create: Create a new queue.az storage queue delete: Delete a queue.
Example: Adding a message to a queue
az storage message put \
--account-name mystorageaccount \
--queue-name myqueue \
--content "Hello, Azure Storage!" \
--account-key YOUR_ACCOUNT_KEY
Table Storage Management
Manage Azure Tables and entities.
Key Commands:
az storage table create: Create a new table.az storage table list: List tables.az storage entity insert: Insert an entity into a table.az storage entity query: Query entities in a table.
Example: Creating a table
az storage table create \
--account-name mystorageaccount \
--name mytable \
--account-key YOUR_ACCOUNT_KEY
Authentication Methods
Azure CLI supports multiple authentication methods for storage commands:
- Account Key: Use
--account-keyor set theAZURE_STORAGE_KEYenvironment variable. - SAS Token: Use
--sas-tokenor set theAZURE_STORAGE_SAS_TOKENenvironment variable. - Azure AD Authentication: If logged in with
az login, the CLI will use your Azure AD credentials (requires appropriate role assignments).
Tips and Best Practices
- Use environment variables for sensitive information like account keys.
- Leverage scripting for repetitive tasks.
- Explore the
--helpflag for detailed command options (e.g.,az storage blob upload --help). - Consider using Azure Key Vault for managing secrets.
For the most up-to-date and detailed information, please refer to the official Azure CLI Storage Documentation.