Forrest logo
back to the azcopy tool

azcopy:tldr:44263

azcopy: Synchronize a local directory and delete files in the destination if they no longer exist in the source.
$ azcopy sync '${path\to\source_directory}' 'https://${storage_account_name}.blob.core.windows.net/${container_name}' --recursive --delete-destination=true
try on your machine

This command uses the Azure CLI (Command-Line Interface) tool called azcopy to synchronize the contents of a local source directory to a destination container within an Azure Blob Storage account. Let's break down the command:

  • azcopy sync: This is the command for syncing the source and destination directories.

  • '${path\to\source_directory}': This is the path to the local source directory that you want to sync. You need to replace ${path\to\source_directory} with the actual path to your source directory.

  • 'https://${storage_account_name}.blob.core.windows.net/${container_name}': This is the URL of the destination container within the Azure Blob Storage account. You need to replace ${storage_account_name} with the name of your storage account, and ${container_name} with the name of your destination container.

  • --recursive: This flag is used to enable syncing subdirectories and their contents as well. Without this flag, only the top-level contents of the source directory would be synced.

  • --delete-destination=true: This flag is used to delete any files in the destination container that do not exist in the source directory. It ensures that the destination is an exact mirror of the source directory.

By running this command, azcopy will compare the source directory with the destination container and copy any missing or updated files from the source to the destination. It will also delete any files in the destination that are not present in the source directory.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the azcopy tool