Last active
April 23, 2024 12:20
-
-
Save andrew-kelleher/031ff5daa8849a9a9c335271f0b3bc08 to your computer and use it in GitHub Desktop.
Azure Function App PowerShell script to backup Blob storage to an Azure File share
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Input bindings are passed in via param block. | |
param($Timer) | |
# Define variables | |
$SrcStgAccURI = "https://sourceblobstg.blob.core.windows.net/" | |
$SrcBlobContainer = "myblobs" | |
$SrcSASToken = SAS_TOKEN_SOURCE | |
$SrcFullPath = "$($SrcStgAccURI)$($SrcBlobContainer)?$($SrcSASToken)" | |
$DstStgAccURI = "https://destinationfilestg.file.core.windows.net/" | |
$DstFileShare = "backupstaging" | |
$DstSASToken = SAS_TOKEN_DESTINATION | |
$DstFullPath = "$($DstStgAccURI)$($DstFileShare)?$($DstSASToken)" | |
# Get the current universal time in the default string format | |
$currentUTCtime = (Get-Date).ToUniversalTime() | |
# The 'IsPastDue' property is 'true' when the current function invocation is later than scheduled. | |
if ($Timer.IsPastDue) { | |
Write-Host "PowerShell timer is running late!" | |
} | |
# Write an information log with the current time. | |
Write-Host "PowerShell timer trigger function ran! TIME: $currentUTCtime" | |
# uncomment to delete azcopy and force download again | |
# del azcopy.exe | |
# Test if AzCopy.exe exists in current folder | |
$WantFile = "azcopy.exe" | |
$AzCopyExists = Test-Path $WantFile | |
Write-Host "AzCopy exists:" $AzCopyExists | |
# Download AzCopy if it doesn't exist | |
If ($AzCopyExists -eq $False) | |
{ | |
Write-Host "AzCopy not found. Downloading..." | |
#Download AzCopy | |
Invoke-WebRequest -Uri "https://aka.ms/downloadazcopy-v10-windows" -OutFile AzCopy.zip -UseBasicParsing | |
#Expand Archive | |
write-host "Expanding archive..." | |
Expand-Archive ./AzCopy.zip ./AzCopy -Force | |
# Copy AzCopy to current dir | |
Get-ChildItem ./AzCopy/*/azcopy.exe | Copy-Item -Destination "./AzCopy.exe" | |
} | |
else | |
{ | |
Write-Host "AzCopy found, skipping download." | |
} | |
# Set env values for AzCopy | |
$env:AZCOPY_LOG_LOCATION = $env:temp+'\.azcopy' | |
$env:AZCOPY_JOB_PLAN_LOCATION = $env:temp+'\.azcopy' | |
# Run AzCopy from source blob to destination file share | |
Write-Host "Backing up storage account..." | |
./azcopy.exe copy $SrcFullPath $DstFullPath --recursive --overwrite=ifsourcenewer |
at the end it worked for me by adding azcopy.exe directly in the package. I suggest you to do the same
I did do that but couldn’t get it working. It didn’t like the path to the log files. It was changing the slash on a windows function app to / rather than . Did you use Linux or windows?
@GuetarniTarik - whats the way to integrate azcopy.exe with the package folder?
Hello Andrew,
I tried to execute this script, but it is not working for me, can you pass on any documentation if it is handy with you.
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for the update @GuetarniTarik I take it you didn’t get any further with it? I raised a ticket with MS but didn’t get any further myself.