Backup SP Online document library locally

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Ryan Yates Ryan Yates 1 year, 1 month ago.

  • Author
  • #35364
    Profile photo of Scott Bunting
    Scott Bunting

    We currently use a 3rd party software to backup our SP document libraries locally to a NAS – it does so through a mapped drive (WebDAV) – this is problematic for many reasons.

    Should I be able to create a powershell script that connect to a document library and copies the files locally? Then on subsequent runs, copies only file that changed? I'm looking to have a sync'd copy locally of the SP document library.

    I know how to connect to the SP Online site with Powershell, but once connected then what? Can I use robocopy to then copy the documents? If so, how does robocopy address the doc. library? by URL once connected?

    I appreciate any thoughts on the topic.

    Thank you

  • #35366
    Profile photo of Bob McCoy
    Bob McCoy

    Have you looked at Robocopy? Comes with Windows and will save a lot of reinventing the wheel.

  • #35377
    Profile photo of Scott Bunting
    Scott Bunting

    Yes, I was thinking I could use Robocopy once connected. Wondering if anyone has done it before with SP Online doc libraries and aware of any gotchas. I'll try to hack my way through it this weekend and see what I can come up with.

  • #35403
    Profile photo of Ryan Yates
    Ryan Yates

    I would use the OfficeDevPnP PowerShell Cmdlets and make use of the Get-SPOFile Cmdlet to do this within a foreach loop with an if statement in there as well.

    Example would be

    $downloadLocation = 'C:\DownloadLocation'
    $date = (get-date).AddDays(-1)
    $ctx = Get-SPOContext
    $list = Get-SPOList -Identity "ListName"
    $files = $list.RootFolder.Files
    foreach ($file in $files) {
        if ($file.TimeLastModified -gt $date) { 
               Get-SPOFile -ServerRelativeUrl $file.ServerRelativeUrl -Path $DownloadLocation -Filename $file.Name }

    That will do what your looking for and the OfficeDevPnP Cmdlets can be downloaded from the PowerShell Galllery with the following Command

    Install-Module OfficeDevPnP.PowerShell.V16.Commands

    or from Github directly

    Hopefully this will be useful for you

You must be logged in to reply to this topic.