Skip to main content

Lab 012: Synchronizing Containers Using the CLI



Requirements

As part of a data migration project, the team lead has tasked the team with migrating data from an existing Azure Blob container to a new Blob container. The existing container contains a substantial amount of data that must be accurately transferred to the new container. The team is responsible for creating the new Blob container and ensuring that all data from the existing container is copied or synced to the new container completely and accurately. It is imperative to perform thorough verification steps to confirm that all data has been successfully transferred to the new container without any loss or corruption.

As a member of the Nautilus DevOps Team, your task is to perform the following:

  1. Create a New Private Azure Blob Container: Name the container xfusion-dest-21957 under the storage account xfusionstorage20694.

  2. Data Migration: Migrate the file xfusion.txt from the existing xfusion-source-10929 container to the new xfusion-dest-21957 container.

  3. Ensure Data Consistency: Ensure that both containers have the file xfusion.txt and confirm the file content is identical in both containers.

  4. Use Azure CLI: Use the Azure CLI to perform the creation and data migration tasks.


Note

The solution can be implemented using both the Azure Cloud Console and the Azure CLI. This document outlines the CLI-based approach to accomplish these tasks. It is recommended to first explore the Azure Cloud Console for hands-on experience and a practical understanding of the process before utilizing the CLI approach, unless specifically instructed otherwise.

Prerequisites

  • Azure CLI is authenticated.
  • Storage account xfusionstorage20694 exists and is accessible.
  • Source container xfusion-source-10929 already contains xfusion.txt.

Steps

RG=$(az group list --query "[?contains(name, 'kml')].name | [0]" --output tsv)
STORAGE_ACCOUNT_NAME="xfusionstorage20694"
SOURCE_CONTAINER="xfusion-source-10929"
DEST_CONTAINER="xfusion-dest-21957"
FILE_NAME="xfusion.txt"

STORAGE_ACCOUNT_KEY=$(az storage account keys list \
--resource-group "$RG" \
--account-name "$STORAGE_ACCOUNT_NAME" \
--query "[0].value" \
--output tsv)

az storage container create \
--name "$DEST_CONTAINER" \
--account-name "$STORAGE_ACCOUNT_NAME" \
--account-key "$STORAGE_ACCOUNT_KEY" \
--public-access off

az storage blob copy start \
--destination-blob "$FILE_NAME" \
--destination-container "$DEST_CONTAINER" \
--account-name "$STORAGE_ACCOUNT_NAME" \
--account-key "$STORAGE_ACCOUNT_KEY" \
--source-container "$SOURCE_CONTAINER" \
--source-blob "$FILE_NAME"

az storage blob download \
--container-name "$SOURCE_CONTAINER" \
--name "$FILE_NAME" \
--file source_xfusion.txt \
--account-name "$STORAGE_ACCOUNT_NAME" \
--account-key "$STORAGE_ACCOUNT_KEY"

az storage blob download \
--container-name "$DEST_CONTAINER" \
--name "$FILE_NAME" \
--file dest_xfusion.txt \
--account-name "$STORAGE_ACCOUNT_NAME" \
--account-key "$STORAGE_ACCOUNT_KEY"

Verification

# Confirm file exists in source and destination
az storage blob list --container-name "$SOURCE_CONTAINER" --account-name "$STORAGE_ACCOUNT_NAME" --account-key "$STORAGE_ACCOUNT_KEY" --query "[?name=='$FILE_NAME'].name" --output table
az storage blob list --container-name "$DEST_CONTAINER" --account-name "$STORAGE_ACCOUNT_NAME" --account-key "$STORAGE_ACCOUNT_KEY" --query "[?name=='$FILE_NAME'].name" --output table

# Confirm copied content matches
diff source_xfusion.txt dest_xfusion.txt
  • If diff returns no output, file contents are identical.

Resources

Azure CLI Docs