Robocopy from NAS to backup Hard drive using Powershell

Sheryl Heier 21 Reputation points
2022-10-08T12:59:56.207+00:00

I am trying to backup a Synology NAS drive to a backup hard drive and get the error ERROR 3 (0x00000003) Getting File System Type of Source The system cannot find the path specified. This is the code I am using:

powershell - robocopy

C:
CLS
Write-host "Checking for F:\Backup_X"
IF (test-path F:\Backup_X) {
write-host "Backing up Z:\synologydrive\Data to F:\Backup_X" -foreground Green
robocopy Z:\synologydrive\data F:\Backup_X\ . /MIR /w:1 /r:1 /XD "#recycle" /log:C:\CAHJobs\Backup_To_X.log /np
}
Else {
write-host "F: drive is not mounted" -foreground RED

}

Write-Host "rnAging Files" -Foreground Green
Write-Host "Zero Days" -Foreground Green
robocopy "c:\Windows\Temp" c:\~temp . /e /move /r:1 /w:1 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null
robocopy c:\Users\usersname\appData\Local\Microsoft\Windows\InetCache\Content.Outlook\D017l9wk c:\~temp . /e /move /r:1 /w:1 /NFL /NDL /NJH /NJS /nc /ns/ /np | Out-Null

Write-Host "7 Days" -Foreground Green
robocopy "c:\data\SPAM" c:\~temp /e /move /minage:7 /r:1 /w:1 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null
robocopy "c:\t" c:\~temp . /e /move /minage:7 /r:1 /w:1 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null
robocopy "c:\users\usersname\appdata\local\google\chrome\user Data\default\cache\" c:\~temp . /e /move /minage:7 /r:1 /w:1 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null
robocopy "c:\users\usersname\appdata\local\google\chrome\user Data\default\Application Cache\Cache\" c:\~temp . /e /move /minage:7 /r:1 /w:1 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null
robocopy "C:\Users\usersname\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook\H63G57WQ" c:\~temp . /e /move /minage:7 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null

Write-Host "20 Days" -Foreground Green
robocopy "c:\data\t" c:\~temp . /e /move /minage:60 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null

Write-Host "rnRemoving Files" -Foreground Green

Remove Files

remove-Item c:\~temp -Force -Recurse
Write-Host "rnComplete" -Foreground Green

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 36,401 Reputation points
    2022-10-08T17:05:29.427+00:00

    Those robocopy's are essentially purging old files. The destination folder is c:\~temp. By using the /move switch and then doing the remove-item, all of those moved files are deleted.

    In Powershell the "#" character indicates a comment. So rather than deleting the lines, just change them into comments so that if you find these folders filling up in the future you can just uncomment them and let the purge process work.

    C:  
    CLS  
    Write-host "Checking for F:\Backup_X"  
    IF (test-path F:\Backup_X) {  
        write-host "Backing up \\synologydrive\Data to F:\Backup_X" -foreground Green  
        robocopy \\synologydrive\data F:\Backup_X\  /MIR /w:1 /r:1 /XD "#recycle" /log:C:\CAHJobs\Backup_To_X.log /np  
    }  
    Else {  
        write-host "F: drive is not mounted" -foreground RED  
    }  
    
    # Write-Host "`r`nAging Files" -Foreground Green  
    # Write-Host "Zero Days" -Foreground Green  
    # robocopy "c:\Windows\Temp" c:\~temp . /e /move /r:1 /w:1 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null  
    # robocopy c:\Users\usersname\appData\Local\Microsoft\Windows\InetCache\Content.Outlook\D017l9wk c:\~temp . /e /move /r:1 /w:1 /NFL /NDL /NJH /NJS /nc /ns/ /np | Out-Null  
    #   
    # Write-Host "7 Days" -Foreground Green  
    # robocopy "c:\data\SPAM" c:\~temp /e /move /minage:7 /r:1 /w:1 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null  
    # robocopy "c:\t" c:\~temp . /e /move /minage:7 /r:1 /w:1 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null  
    # robocopy "c:\users\usersname\appdata\local\google\chrome\user Data\default\cache\" c:\~temp . /e /move /minage:7 /r:1 /w:1 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null  
    # robocopy "c:\users\usersname\appdata\local\google\chrome\user Data\default\Application Cache\Cache\" c:\~temp . /e /move /minage:7 /r:1 /w:1 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null  
    # robocopy "C:\Users\usersname\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook\H63G57WQ" c:\~temp . /e /move /minage:7 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null  
    #   
    # Write-Host "20 Days" -Foreground Green  
    # robocopy "c:\data\t" c:\~temp . /e /move /minage:60 /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null  
    #   
    # Write-Host "`r`nRemoving Files" -Foreground Green  
    # # Remove Files  
    # remove-Item c:\~temp -Force -Recurse  
    Write-Host "`r`nComplete" -Foreground Green  
    
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. MotoX80 36,401 Reputation points
    2022-10-08T13:41:16.88+00:00

    You have 9 robocopy calls, which one is failing? On several of them you have a period after the destination directory. Remove that or replace it with a valid file specification. You also double up on backslashes, change Z:\synologydrive to Z:\synologydrive. Do you see a folder named synologydrive on the Z drive, or is that supposed to be a network name? In that case get rid of "Z:" and just use the UNC path.

    Does Get-Childitem produce a directory list of the source files?

    0 comments No comments

  2. Sheryl Heier 21 Reputation points
    2022-10-08T13:55:47.597+00:00

    Hi - the script was written by my late husband so not sure I need all those other calls. All I really want is to backup just the NAS to another hard drive. I think the removal of the Z: letter infront of the NAS drive might be working as it is running now. How can i clean up this script to just run the backup? Thanks for you help.


  3. Sheryl Heier 21 Reputation points
    2022-10-08T17:16:33.857+00:00

    Thanks you for all your help!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.