Skip to content

Instantly share code, notes, and snippets.

@esell
Created December 13, 2017 16:35
Show Gist options
  • Save esell/4d9c3a25ec59e281ca753974daab281d to your computer and use it in GitHub Desktop.
Save esell/4d9c3a25ec59e281ca753974daab281d to your computer and use it in GitHub Desktop.
Backup a blob from one sa to another
Write-Output "PowerShell Timer trigger function executed at:$(get-date)";
# Create src/dest contexts
# DEST_KEY & SRC_KEY are set as environment variables in app settings
$DestContext = New-AzureStorageContext -StorageAccountName "destStorageAccountName" -StorageAccountKey $env:DEST_KEY
$SrcContext = New-AzureStorageContext -StorageAccountName "srcStorageAccountName" -StorageAccountKey $env:SRC_KEY
# Get timestamp
$timestamp = Get-Date -Format o | foreach {$_ -replace ":", "."}
# Set dest filename
$destFilename = "destFilename" + $timestamp
# Copy blob
Start-AzureStorageBlobCopy -SrcBlob "srcFilename" -SrcContainer "copyFrom" -DestContainer "copyto" -DestBlob $destFilename -SrcContext $SrcContext -DestContext $DestContext
# List blobs in dest container
Get-AzureStorageBlob -Container "copyto" -Context $DestContext | select Name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment