Managing Azure Storage with Azure CLI
The Azure Command-Line Interface (CLI) provides a powerful and flexible way to manage your Azure Storage resources. This documentation covers common commands for interacting with Blob storage, File storage, Queue storage, and Table storage.
Prerequisites
Before you begin, ensure you have the Azure CLI installed and are logged in to your Azure account:
az login
Blob Storage
Blob storage is optimized for storing massive amounts of unstructured data, such as text or binary data. This includes anything that can be stored as an object or file.
Key Operations
- Create a storage account:
az storage account create --name <storage-account-name> --resource-group <resource-group-name> --location <location> --sku Standard_LRS
az storage blob list --container-name <container-name> --account-name <storage-account-name>
az storage blob upload --container-name <container-name> --file <local-file-path> --name <blob-name> --account-name <storage-account-name>
az storage blob download --container-name <container-name> --name <blob-name> --file <local-file-path> --account-name <storage-account-name>
az storage blob delete --container-name <container-name> --name <blob-name> --account-name <storage-account-name>
az storage container create
, az storage container list
, and az storage container delete
commands.
File Storage
Azure Files offers fully managed cloud file shares that are accessible via the industry-standard Server Message Block (SMB) protocol or Network File System (NFS) protocol. This allows you to lift and shift on-premises applications that rely on file shares to Azure.
Key Operations
- Create a file share:
az storage share create --name <share-name> --account-name <storage-account-name> [--quota <size-in-GB>]
az storage file list --share-name <share-name> --account-name <storage-account-name> [--source-path <directory-path>]
az storage file upload --share-name <share-name> --source <local-file-path> --path <destination-file-path> --account-name <storage-account-name>
az storage file download --share-name <share-name> --path <file-path> --destination <local-directory-path> --account-name <storage-account-name>
Queue Storage
Queue storage is used to store large numbers of messages that can be accessed and processed by multiple clients. It's ideal for decoupling application components.
Key Operations
- Create a queue:
az storage queue create --name <queue-name> --account-name <storage-account-name>
az storage message list --queue-name <queue-name> --account-name <storage-account-name> [--num-messages <count>]
az storage message put --queue-name <queue-name> --content <message-content> --account-name <storage-account-name>
az storage message delete --queue-name <queue-name> --id <message-id> --pop-receipt <pop-receipt-value> --account-name <storage-account-name>
Table Storage
Table storage stores schemaless data in NoSQL key-value stores. It's suitable for flexible datasets like customer data, address books, or other kinds of metadata.
Key Operations
- Create a table:
az storage table create --name <table-name> --account-name <storage-account-name>
az storage entity insert --table <table-name> --entity <entity-json> --account-name <storage-account-name>
az storage entity query --table <table-name> --account-name <storage-account-name> [--filter <odata-filter-expression>]
az storage entity delete --table <table-name> --partition-key <partition-key-value> --row-key <row-key-value> --account-name <storage-account-name>