Adrian G
Adrian G

Reputation: 11

xcopy and Robocopy deleting destination file

I'm trying to copy some files from one server to another's shared folder, the thing is, it works sometimes, but quite often the xcopy and robocopy commands delete the destination file upon failure, even if the backup fails I need the files to stay there.

To get into details, on the server where I'm running the commands (Windows 10) I have a bunch of Tableau files (.twbx) which are updated via a .JAR file that I run every morning with a Scheduled task.

After the files are updated I copy them to another server's share using xcopy (I later tried Robocopy to see if the problem stops happening), but when I check in the morning, the destination file is missing. It works sporadically, the issue is I need those files to always be in the share folder.

My .bat file looks like this:

I sequentially run the copy commands (one for each file since they are in diferent folder).

Robocopy E:\Tableau\TableauFileFolder \\shareserver\sharefolder\Tableau\TableauFileFolder TableauFile.twbx /mt /r:0 /log+:E:\Tableau\LogFile.log
Robocopy E:\Tableau\TableauFileFolder2 \\shareserver\sharefolder\Tableau\TableauFileFolder2 TableauFile2.twbx /mt /r:0 /log+:E:\Tableau\LogFile.log
Etc...

For xcopy I'm using:

xcopy /s/y E:\Tableau\TableauFileFolder\TableauFile.twbx \\shareserver\sharefolder\K2BAnalytics\TableauFileFolder

Directory structure is like so, on the server where I'm running the commands I have:

E:
  |-->Tableau
    |-->ShareFileFolder
      |-->ShareFile.twbx
    |-->ShareFileFolder2
      |-->ShareFile2.twbx

Share server:

sharefolder:
  |-->Tableau
    |-->ShareFileFolder
      |-->ShareFile.twbx
    |-->ShareFileFolder2
      |-->ShareFile2.twbx

My log file shows this error on the missing files:

2020/11/19 04:31:57 ERROR 0 (0x00000000) r E:\Tableau\TableauFileFolder\TableauFile.twbx
The operation completed successfully.

Admin user running the commands has full control permission on the Tableau folder of the share.

I've been having this issue for a while and I can't find a solution anywhere. I'm not using /MIR so I don't know what could be causing the destination files to be deleted.

Upvotes: 0

Views: 2494

Answers (2)

BtF
BtF

Reputation: 101

A robocopy source target /b /MT:1 run with administrator privileges could do the trick for you.

In my similar case a source file was being locked by another process and:

  • /b makes the robocopy leave the target file untouched if it cannot access it (but it requires administrator privileges)
  • /mt:<n> or just /mt makes robocopy notice the "ERROR 0" and retry.

As I run the robocopy manually, I just use robocopy source target /MT:1 - seeing the error I can stop the application locking the file and start it after I am done.

Official docs: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy

Upvotes: 0

Adrian G
Adrian G

Reputation: 11

As people suggested in the comments, I allowed Robocopy to make a few attempts using /R:n which has helped mitigate the issue a lot, but still isn't infallible. Some sugggested to use a smarter file copying task but I don't know of any good alternatives to Robocopy.

My commands are now like so:

Robocopy E:\Tableau\TableauFileFolder \\shareserver\sharefolder\Tableau\TableauFileFolder TableauFile.twbx /mt /r:5 /w:10 /log+:E:\Tableau\LogFile.log

Upvotes: 1

Related Questions