question

jayanthiramprakash-9905 avatar image
0 Votes"
jayanthiramprakash-9905 asked RichMatheisen-8856 commented

Robocopy not deleting source files

Hi Experts,

Could you please advice on the following. Thank you.


1) Robocopy is having issues deleting the source files after the move. Below is the error. (from Robocopy.log)

ERROR 32 (0x00000020) Deleting Source Directory \\server01\Folder1\
The process cannot access the file because it is being used by another process.

2) Also, I am not getting the error email. Am I missing something? (code below)


     $SourceFolder1 = "\\server01\Folder1"
     $TargetFolder1 = "\\server02\Folder2"
        
        
     robocopy $SourceFolder1 $TargetFolder1 *.log  /XX /Move /LOG+:Robocopy.log
        
        
     if ($lastexitcode -ne 0)
      {
        
      Send-MailMessage -From "alerts@company.com" -To  "servicedesk@company.com" -Subject "Automated message: Robo copy failed" -Body  "Robocopy failed with exit code: $lastexitcode"  -SmtpServer "smtp.company.com"
        
     }




windows-serverwindows-server-powershellwindows-server-backup
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

Is the directory Folder1 in use on SERVER01?

Does the server smtp.compcny.com accept unauthenticated connections on port 25? Perhaps you should be using port 587 and providing credentials?

If you want to know what the error is, wrap the Send-MailMessage cmdlet in a Try/Catch block and add "-ErrorAction STOP" to the cmdlet. In the Catch block display or record the error for examination.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

jayanthiramprakash-9905 avatar image
0 Votes"
jayanthiramprakash-9905 answered

Hi Rich,

Thanks for the response. Email issue is sorted now.

However, the source files are still not deleted after the move. I do not see any connections in "Open files" or "Sessions" in computer management. What's the best to see if the folder is in use by some process? Thank you.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
1 Vote"
RichMatheisen-8856 answered

Try some of these utilities:
find-process-locked-file-openfiles-utility



As for robocopy, I've hardly ever used it but it seems to me that you're trying to remove the source directory and that directory is in use. Perhaps adding the "/E" switch to the parameters (i.e., leave the source directory in place) and deal with the directory's removal in some other way after the files have been moved.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

jayanthiramprakash-9905 avatar image
0 Votes"
jayanthiramprakash-9905 answered RichMatheisen-8856 commented

Hi Rich,

Thanks for the response.

I used the tools and looks like the files are not locked. Looks like Robocopy is trying to delete the source folders and hence the error. Adding the "/E" switch did not help.
Is there a way to fine tune robocopy not to delete the folders but only the log files? Thank you.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm afraid I'm not the person to ask any questions of robocopy!

The only idea I have is to COPY the structure, then unmap the share using your source directory on the server (if there is one), and then remove the source directory.

The issue here isn't PowerShell, Windows Server, or Windows Backup. There are several answers to your question on sites that I'm not a member of, though. You could try searching for "robocopy do not delete source directory".

0 Votes 0 ·