Skip to content

AZCOPY DSC Class Based Resource to sync files from Azure Blob Storage.

License

Notifications You must be signed in to change notification settings

brwilkinson/AZCOPYDSCDir

Repository files navigation

AZCOPYDSC

PowerShell AZCOPY DSC Class based Resource

This is a DSC Resource for performing File sync tasks with Azure File Shares

azcopy sync /?

Requirements

  • PowerShell Version 5.0 +
  • Server 2012 +
    # sample configuation data

            # Blob copy with Managed Identity - Oauth2
            AZCOPYDSCDirPresentSource   = @(

                @{
                    SourcePathBlobURI = 'https://{0}.blob.core.windows.net/source/PSModules/'
                    DestinationPath   = 'F:\Source\PSModules\'
                },

                @{
                    SourcePathBlobURI = 'https://{0}.blob.core.windows.net/source/Tools/'
                    DestinationPath   = 'F:\Source\Tools\'
                }
            )
Configuration AppServers
{
    Param (
        [String]$StorageAccountName,
        [String]$clientIDGlobal
    )

    node $AllNodes.NodeName
    {
        $StringFilter = '\W', ''
        #-------------------------------------------------------------------     
        foreach ($AZCOPYDSCDir in $Node.AZCOPYDSCDirPresentSource)
        {
            $Name = ($AZCOPYDSCDir.SourcePath -f $StorageAccountName + $AZCOPYDSCDir.DestinationPath) -replace $StringFilter 
            AZCOPYDSCDir $Name
            {
                SourcePath              = ($AZCOPYDSCDir.filesSourcePath -f $StorageAccountName)
                DestinationPath         = $AZCOPYDSCDir.filesDestinationPath
                Ensure                  = 'Present'
                ManagedIdentityClientID = $clientIDGlobal
                LogDir                  = 'F:\azcopy_logs'
            }
            $dependsonDirectory += @("[AZCOPYDSCDir]$Name")
        }

Full sample available here

Invoke the resource directly to sync the files

$ht = @{
    SourcePath              = 'https://storage01.blob.core.windows.net/source/PSModules/'
    DestinationPath         = 'F:\Source\PSModules\'
    Ensure                  = 'Present'
    ManagedIdentityClientID = '219fa169-9031-49cc-b4cb-1850bc5bf6b4'
    LogDir                  = 'F:\azcopy_logs'
}

Invoke-DscResource -Name AZCOPYDSCDir -Method Set -ModuleName AZCOPYDSCDir -Property $ht -Verbose

About

AZCOPY DSC Class Based Resource to sync files from Azure Blob Storage.

Resources

License

Stars

Watchers

Forks