Wednesday, December 11, 2013

Script for File copy Older than X Days | ROBOCOPY Batch file

Hey All,

Issue :

One more challenge I faced yesterday.
Robocopy batch files which I scheduled were getting failed with error code 0x1

Observation : All robocopy schedules were getting failed with error code 0x1
One more thing I noticed is that the Task manager was showing multiple instances of Robocopy exe.

Task manager gave way to the solution

Solution :

After googling number of forums, I found switch to exit the Robocopy at the end. I added it at the end of command, but it did not work.

It gave error 0x80 :  Quitting : /QUIT Specified on Command Line.

After that I tried one more option. Defining one more line of code and specifying the /QUIT option there.

e.g.
*****************************************************************
@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
robocopy "\\share\source" "D:\Destination" *.xml /MAXAGE:3 /LOG+:"D:\Logs\%mydate%.log" /NP
 

robocopy /QUIT
*****************************************************************
 What does above script does :
  • Copies files which are not older than 3 Days from source to destination
  • Stores the logs Datewise (You can add %mytime% if you want time also)
  • Copies only XML extension (You can specify *.* if you want to copy all files)
Its working fine now.

Hope this helps to you as well.

No comments:

Post a Comment

Solved : The user profile failed to attach. The process cannot access the file becase it is being used by another process

Issue :  The user profile failed to attach. Please contact Support. Status : 0x0000000B, Message: Cannot open virtual disk Error Code: 0x000...