Home > Net >  Backup Sharepoint Online with Azure functions
Backup Sharepoint Online with Azure functions

Time:01-06

Is there a way to generate a sharepoint backup online using azure functions?

I have already authenticated the tenant using managed identity

The idea would be to download all the files in the documents and upload them to an azure storage account

I used this code but I get an error:

using namespace System.Net

param($Request, $TriggerMetadata)
   
$TenantSiteURL = "https://tenant.sharepoint.com"
$SiteRelativeURL = "/sites/BackupSource"
$LibraryName = "Documenti Condivisi"
$DownloadPath ="\Temp\Docs"

#Connect-PnPOnline -ManagedIdentity 
Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentity
Write-Warning "Connesso"
#Set-Location -Path SPO:\$SiteRelativeURL

Get-PnPMicrosoft365Group

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
})


2022-01-03T16:58:32.983 [Information] Executing 'Functions.HttpTrigger1' (Reason='This function was programmatically called via the host APIs.', Id=09c1fe95-6b6e-4e85-8c8f-815e37e99d04)
2022-01-03T16:58:40.915 [Information] OUTPUT:
2022-01-03T16:58:41.541 [Information] OUTPUT: Account   SubscriptionName TenantId                             Environment
2022-01-03T16:58:41.542 [Information] OUTPUT: -------   ---------------- --------                             -----------
2022-01-03T16:58:41.549 [Information] OUTPUT: MSI@50342                  --- AzureCloud
2022-01-03T16:58:41.549 [Information] OUTPUT:
2022-01-03T16:58:43.530 [Error] ERROR: Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.Exception             :Type              : System.Management.Automation.ParameterBindingExceptionMessage           : Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.ErrorId           : AmbiguousParameterSetLine              : 13Offset            : 1CommandInvocation :MyCommand        : Connect-PnPOnlineBoundParameters  :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     :Length : 3Length : 15Values   :Length : 30IsPresent : TrueSyncRoot :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     :Length : 3Length : 15Values   :Length : 30IsPresent : TrueSyncRoot :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     :Length : 3Length : 15Values   :Length : 30IsPresent : TrueSyncRoot :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     :Length : 3Length : 15Values   :Length : 30IsPresent : TrueSyncRoot :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     :Length : 3Length : 15Values   :Length : 30IsPresent : TrueSyncRoot :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     :Length : 3Length : 15Values   :Length : 30IsPresent : TrueSyncRoot :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     : …Values   : …SyncRoot : …ScriptLineNumber : 13OffsetInLine     : 1HistoryId        : 1ScriptName       : C:\home\site\wwwroot\HttpTrigger1\run.ps1Line             : Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentityPositionMessage  : At C:\home\site\wwwroot\HttpTrigger1\run.ps1:13 char:1  Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentity  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot     : C:\home\site\wwwroot\HttpTrigger1PSCommandPath    : C:\home\site\wwwroot\HttpTrigger1\run.ps1InvocationName   : Connect-PnPOnlinePipelineLength   : 1PipelinePosition : 1CommandOrigin    : InternalErrorRecord       :Exception             :Type    : System.Management.Automation.ParentContainsErrorRecordExceptionMessage : Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.HResult : -2146233087CategoryInfo          : InvalidArgument: (:) [Connect-PnPOnline], ParentContainsErrorRecordExceptionFullyQualifiedErrorId : AmbiguousParameterSet,PnP.PowerShell.Commands.Base.ConnectOnlineInvocationInfo        :MyCommand        : Connect-PnPOnlineScriptLineNumber : 13OffsetInLine     : 1HistoryId        : 1ScriptName       : C:\home\site\wwwroot\HttpTrigger1\run.ps1Line             : Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentityPositionMessage  : At C:\home\site\wwwroot\HttpTrigger1\run.ps1:13 char:1  Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentity  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot     : C:\home\site\wwwroot\HttpTrigger1PSCommandPath    : C:\home\site\wwwroot\HttpTrigger1\run.ps1CommandOrigin    : InternalScriptStackTrace      : at <ScriptBlock>, C:\home\site\wwwroot\HttpTrigger1\run.ps1: line 13TargetSite        :Name          : ThrowAmbiguousParameterSetExceptionDeclaringType : System.Management.Automation.CmdletParameterBinderController, System.Management.Automation, Version=7.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35MemberType    : MethodModule        : System.Management.Automation.dllStackTrace        :at System.Management.Automation.CmdletParameterBinderController.ThrowAmbiguousParameterSetException(UInt32 parameterSetFlags, MergedCommandParameterMetadata bindableParameters)at System.Management.Automation.CmdletParameterBinderController.ValidateParameterSets(Boolean prePipelineInput, Boolean setDefault)at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)at System.Management.Automation.CommandProcessor.BindCommandLineParameters()at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)--- End of stack trace from previous location where exception was thrown ---at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)Data              : System.Collections.ListDictionaryInternalSource            : System.Management.AutomationHResult           : -2146233087CategoryInfo          : InvalidArgument: (:) [Connect-PnPOnline], ParameterBindingExceptionFullyQualifiedErrorId : AmbiguousParameterSet,PnP.PowerShell.Commands.Base.ConnectOnlineInvocationInfo        :MyCommand        : Connect-PnPOnlineScriptLineNumber : 13OffsetInLine     : 1HistoryId        : 1ScriptName       : C:\home\site\wwwroot\HttpTrigger1\run.ps1Line             : Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentityPositionMessage  : At C:\home\site\wwwroot\HttpTrigger1\run.ps1:13 char:1  Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentity  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot     : C:\home\site\wwwroot\HttpTrigger1PSCommandPath    : C:\home\site\wwwroot\HttpTrigger1\run.ps1CommandOrigin    : InternalScriptStackTrace      : at <ScriptBlock>, C:\home\site\wwwroot\HttpTrigger1\run.ps1: line 13Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result: ERROR: Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.Exception             :Type              : System.Management.Automation.ParameterBindingExceptionMessage           : Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.ErrorId           : AmbiguousParameterSetLine              : 13Offset            : 1CommandInvocation :MyCommand        : Connect-PnPOnlineBoundParameters  :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     :Length : 3Length : 15Values   :Length : 30IsPresent : TrueSyncRoot :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     :Length : 3Length : 15Values   :Length : 30IsPresent : TrueSyncRoot :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     :Length : 3Length : 15Values   :Length : 30IsPresent : TrueSyncRoot :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     :Length : 3Length : 15Values   :Length : 30IsPresent : TrueSyncRoot :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     :Length : 3Length : 15Values   :Length : 30IsPresent : TrueSyncRoot :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     :Length : 3Length : 15Values   :Length : 30IsPresent : TrueSyncRoot :Comparer : System.OrdinalIgnoreCaseComparerCount    : 2Keys     : …Values   : …SyncRoot : …ScriptLineNumber : 13OffsetInLine     : 1HistoryId        : 1ScriptName       : C:\home\site\wwwroot\HttpTrigger1\run.ps1Line             : Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentityPositionMessage  : At C:\home\site\wwwroot\HttpTrigger1\run.ps1:13 char:1  Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentity  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot     : C:\home\site\wwwroot\HttpTrigger1PSCommandPath    : C:\home\site\wwwroot\HttpTrigger1\run.ps1InvocationName   : Connect-PnPOnlinePipelineLength   : 1PipelinePosition : 1CommandOrigin    : InternalErrorRecord       :Exception             :Type    : System.Management.Automation.ParentContainsErrorRecordExceptionMessage : Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.HResult : -2146233087CategoryInfo          : InvalidArgument: (:) [Connect-PnPOnline], ParentContainsErrorRecordExceptionFullyQualifiedErrorId : AmbiguousParameterSet,PnP.PowerShell.Commands.Base.ConnectOnlineInvocationInfo        :MyCommand        : Connect-PnPOnlineScriptLineNumber : 13OffsetInLine     : 1HistoryId        : 1ScriptName       : C:\home\site\wwwroot\HttpTrigger1\run.ps1Line             : Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentityPositionMessage  : At C:\home\site\wwwroot\HttpTrigger1\run.ps1:13 char:1  Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentity  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot     : C:\home\site\wwwroot\HttpTrigger1PSCommandPath    : C:\home\site\wwwroot\HttpTrigger1\run.ps1CommandOrigin    : InternalScriptStackTrace      : at <ScriptBlock>, C:\home\site\wwwroot\HttpTrigger1\run.ps1: line 13TargetSite        :Name          : ThrowAmbiguousParameterSetExceptionDeclaringType : System.Management.Automation.CmdletParameterBinderController, System.Management.Automation, Version=7.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35MemberType    : MethodModule        : System.Management.Automation.dllStackTrace        :at System.Management.Automation.CmdletParameterBinderController.ThrowAmbiguousParameterSetException(UInt32 parameterSetFlags, MergedCommandParameterMetadata bindableParameters)at System.Management.Automation.CmdletParameterBinderController.ValidateParameterSets(Boolean prePipelineInput, Boolean setDefault)at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)at System.Management.Automation.CommandProcessor.BindCommandLineParameters()at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)--- End of stack trace from previous location where exception was thrown ---at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)Data              : System.Collections.ListDictionaryInternalSource            : System.Management.AutomationHResult           : -2146233087CategoryInfo          : InvalidArgument: (:) [Connect-PnPOnline], ParameterBindingExceptionFullyQualifiedErrorId : AmbiguousParameterSet,PnP.PowerShell.Commands.Base.ConnectOnlineInvocationInfo        :MyCommand        : Connect-PnPOnlineScriptLineNumber : 13OffsetInLine     : 1HistoryId        : 1ScriptName       : C:\home\site\wwwroot\HttpTrigger1\run.ps1Line             : Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentityPositionMessage  : At C:\home\site\wwwroot\HttpTrigger1\run.ps1:13 char:1  Connect-PnPOnline -Url $TenantSiteURL -ManagedIdentity  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot     : C:\home\site\wwwroot\HttpTrigger1PSCommandPath    : C:\home\site\wwwroot\HttpTrigger1\run.ps1CommandOrigin    : InternalScriptStackTrace      : at <ScriptBlock>, C:\home\site\wwwroot\HttpTrigger1\run.ps1: line 13Exception: Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.Stack:    at System.Management.Automation.CmdletParameterBinderController.ThrowAmbiguousParameterSetException(UInt32 parameterSetFlags, MergedCommandParameterMetadata bindableParameters)at System.Management.Automation.CmdletParameterBinderController.ValidateParameterSets(Boolean prePipelineInput, Boolean setDefault)at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)at System.Management.Automation.CommandProcessor.BindCommandLineParameters()at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)--- End of stack trace from previous location where exception was thrown ---at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2022-01-03T16:58:43.540 [Warning] WARNING: Connesso
2022-01-03T16:58:43.657 [Error] ERROR: There is currently no connection yet. Use Connect-PnPOnline to connect.

CodePudding user response:

There is no PowerShell command available for backup and restore in SharePoint Online.

Backup solutions for SharePoint online here

you can back up a SharePoint online Azure with MABS. Refer here

  •  Tags:  
  • Related