I want to run a scheduled script after running a Robocopy Script, which moves files between remote servers.
The requirement of this script is that, it will check whether the Robocopy script has successfully completed its operation of copying from Source Directory to Destination Directory.
If yes, then this script will purge files and folders from Source Directory .
My question is how to find out whether the Robocopy script which was run before has successfully done its job ?
You can use the exit codes for robocopy:
The return code from Robocopy.exe is a bitmap, defined as follows:
Error Meaning if set 0 No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized. 1 One or more files were copied successfully (that is, new files have arrived). 2 Some Extra files or directories were detected. No files were copied. Examine the output log for details. 4 Some Mismatched files or directories were detected. Examine the output log. Housekeeping might be required. 8 Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further. 16 Serious error. Robocopy did not copy any files. Either a usage error or an error due to insufficient access privileges on the source or destination directories. These can be combined, giving a few extra exit codes:
Error Meaning if set 3 (2+1) Some files were copied. Additional files were present. No failure was encountered. 5 (4+1) Some files were copied. Some files were mismatched. No failure was encountered. 6 (4+2) Additional files and mismatched files exist. No files were copied and no failures were encountered. This means that the files already exist in the destination directory 7 (4+1+2) Files were copied, a file mismatch was present, and additional files were present. An Exit Code of 0-7 is success and any value >= 8 indicates that there was at least one failure during the copy operation. Some deployment tools assume that any Exit Code greater than 0 is an error.
Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With