Link to home
Start Free TrialLog in
Avatar of SeaSenor
SeaSenorFlag for United States of America

asked on

Robocopy job file question

Any way to create a job file (.rcj) of this?:

robocopy /copyall  \\fileserver\folder1
robocopy /copyall  \\fileserver\folder1
robocopy /copyall  \\fileserver\folder3
robocopy /copyall  \\fileserver\folder4
Avatar of oBdA

What exactly is it that you want to do? What you listed above is not valid robocopy syntax.
Here is an example--working in production example of one that works
robocopy T:\ E:\ /E /XJ /W:1 /R:0 /ZB /LOG:T:\Backup\Logs\RoboT2E.Txt /TEE /SAVE:T:\Backup\Jobs\DataT2E
Notice this option /SAVE:T:\Backup\Jobs\DataT2E --this creates a job file I can then use robocopy to call that job file instead of the syntax above

RoboCopy /job:T:\Backup\Jobs\DATAHT2E.RCJ

So you can either have robocopy build a job file for you or you can build one yourself--I suggest you have robocopy do it and once it does what you want, use the resulting file to run robocopy
here is a copy of the file robocopy created for me, which I then call using

RoboCopy /job:T:\Backup\Jobs\DATAHT2E.RCJ

Start of file DATAHT2E.RCJ
:: Created by Enola on Fri May 07 2010 at 08:45:12

:: Source Directory :
      /SD:t:\      :: Source Directory.

:: Destination Directory :
      /DD:e:\      :: Destination Directory.

:: Include These Files :
      /IF            :: Include Files matching these names
::            *.*      :: Include all names (currently - Command Line may override)

:: Exclude These Directories :
      /XD            :: eXclude Directories matching these names
::                  :: eXclude no names (currently - Command Line may override)

:: Exclude These Files :
      /XF            :: eXclude Files matching these names
::                  :: eXclude no names (currently - Command Line may override)
:: Copy options :
      /S            :: copy Subdirectories, but not empty ones.
      /E            :: copy subdirectories, including Empty ones.
      /COPY:DAT      :: what to COPY for files (default is /COPY:DAT).
      /ZB            :: use restartable mode; if access denied use Backup mode.
:: Retry Options :
      /R:0            :: number of Retries on failed copies: default 1 million.
      /W:1            :: Wait time between retries: default is 30 seconds.
:: Logging Options :
      /LOG:T:\Backup\Logs\DataT2e.Txt      :: output status to LOG file (overwrite existing log).
      /TEE            :: output to console window, as well as the log file.
Avatar of SeaSenor


ok.. thanks for responding you all.
let me re-phrase my question to help clarify what I'm trying to do. It may/may not be possible.
I have my daily backups set like so -
Monday thru Friday scheduled tasks - calls a .bat file with the following syntax:

set day=Monday
 robocopy /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:c:\outputfolder\%day%Log.txt /NFL /NDL  \\fileserver\folder1  c:\outputfolder\%day%\folder1
 robocopy /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG+:c:\outputfolder\%day%Log.txt /NFL /NDL  \\fileserver\folder2  c:\outputfolder\%day%\folder2
 robocopy /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG+:c:\outputfolder\%day%Log.txt /NFL /NDL  \\fileserver\folder3  c:\outputfolder\%day%\folder3
 robocopy /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG+:c:\outputfolder\%day%Log.txt /NFL /NDL  \\fileserver\folder4  c:\outputfolder\%day%\folder4

My question there a way to set multiple source and destination directories in a job(.rcj) file?
I have a Monday, Tuesday, Wednesday, Thursday, Friday1, Friday2, Friday3, Friday4, as well as January thru December .bat files scheduled to run these robocopy commands for a standard backup rotation set.
my dilemma is, when i add a folder to the backup set, i have to modify each and every one of the .bat files with a new line of code to include the source and destination directory of the new folder.
My thinking is, that i could have one job file that each .bat file references and i would only have to change the source and destination in the job file.

make sense?

You can do that with a simple "for" loop, if the folder names is indeed like in your description:

set day=Monday
set FolderList="Folder1" "Folder2" "Folder3" "Folder4"
if exist "c:\outputfolder\%day%Log.txt" del "c:\outputfolder\%day%Log.txt"
for %%a in (%FolderList%) do (
robocopy "\\fileserver\%%~a" "C:\outputfolder\%day%\%%~a"  /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG+:c:\outputfolder\%day%Log.txt /NFL /NDL

Open in new window

would i have to do it to each and every .bat file?
oBdA: would I have to edit the folder list in each of my .bat files with that configuration?
sorry.. i'm not great with programming.  I know you couldn't tell :)
Yes; but the list could be stored in an external file as well, so all scripts could read the same file.
But there may be a better solution as well.
Did I understood you correctly that you have several different batch files that you call from several different scheduled tasks, and that the batch files only differ in the "day" variable?
In this case, you could just pass the day as argument to a single batch script:

if "%~1"=="" (
  echo Syntax: %~nx0 Weekday
  goto :eof
set day=%~1
set FolderList="Folder1" "Folder2" "Folder3" "Folder4"
if exist "c:\outputfolder\%day%Log.txt" del "c:\outputfolder\%day%Log.txt"
for %%a in (%FolderList%) do (
  robocopy "\\fileserver\%%~a" "C:\outputfolder\%day%\%%~a"  /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG+:c:\outputfolder\%day%Log.txt /NFL /NDL

Open in new window

In the tasks, you would then just add the day as argument for the batch; let's say you saved the script above as C:\Scripts\BackupRotation.cmd.
For the monday task, you'd just schedule
C:\Scripts\BackupRotation.cmd monday
The same way you'd run it from a command prompt.

Oh, and I just noted that there's a closing bracket missing in the script above (the last line), so that script won't work "out of the box", sorry.
1) You can have multiple source and destination in the robocopy job file
2) You can also run all your scheduled tasks from one batch file by say If %day% = Monday run this job
if Tuesday the next and so on.
yes you are correct... the batch files only differ in the "day" variable.....which in reality, could be a month, or even a year end backup, so it's just "the" variable.  and i know you know that already :)

i do apologize, but i am not very good with scripting.  Where in the above text does it show that the folder list is being called from a different file?  or does it?

I don't mind having the .bat files having the day/month/year set as the variable. Those .bat files should never change as long as I can get the Source folder and the output folder to change as I please from an external file. .. but at the same time, I don't care to have one file that does it all either.

Lastly, I see a bracket on line 10 in the above that not the closer?
Avatar of oBdA

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I will write a batch file for you and get it back to you. Can't do it now so will be later this afternoon. I will write it so it runs from one file and copies data based on what day of the week it is. It will not address the month end and year end backup--but you can easily address that once you have this file to start off with.  If you find a solution before 4 or 5Pm today please let me know so my time isn't wasted--thanks!
that's getting close.
It gives an error that the /LOG+:c:\outputfolder\%day%Log.txt is invalid parameter.
I think maybe because there isn't a log file to append to as the log file is being delted?

Lionelmm -

i would love to see the batch wouldn't be a waste of time at all.
Please write it if you don't mind doing so.
No, robocopy doesn't care whether the log file actually exists when using /log+
Make sure that there's no space directly after "set day=monday"
And if the real name of "outputfolder" contains a space, you need quotes around the path:
robocopy "\\fileserver\%%~a" "C:\outputfolder\%day%\%%~a"  /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG+:"C:\outputfolder\%day%Log.txt" /NFL /NDL
Run this for me and tell me what you get--just want to make sure you have the right date/time setup
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do Set Day=%%i
lionelmm -
if you mean run it in a cmd window I did...

was unexpected at this time.

no sorry you would have to run it from a batch file--sorry my bad
set day=Tue
Sorry about not getting you a complete batch file--client's server crashed--worked on and still working on it. Will get it to you ASAP.
oBdA -
Your script is working fine it appears.
Like a big dummy I had connected to the share through a path and ran the script, which executed it on my machine. Not a problem, but i had changed the output to Drive e:  which is a CD on my computer.
Therefore the error i mentioned. After executing it on the proper machine, it worked great.

lionelmm -
thanks.. no hurry.
and good luck with the server.
@Echo on
Rem      Batch File to run RoboCopy to Folder from Server
Rem      Created on 2011-02-16

Rem      Because of this parameter you can run this file everyday--it will set the %day% (Day) for you
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do Set day=%%i

Rem       I like what oBdA has done with his scripting but since I don't have experience with it, I am doing it this way.
Rem      With oBdA's way you can add the additional folder lists to the external file
Rem      With my way you would have to add another Set Folder= line

Set Folder=folder1
robocopy /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:c:\outputfolder\%day%Log.txt /NFL /NDL  \\fileserver\%Folder%  c:\outputfolder\%day%\%Folder%

Set Folder=folder2
robocopy /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:c:\outputfolder\%day%Log.txt /NFL /NDL  \\fileserver\%Folder%  c:\outputfolder\%day%\%Folder%

Set Folder=folder3
robocopy /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:c:\outputfolder\%day%Log.txt /NFL /NDL  \\fileserver\%Folder%  c:\outputfolder\%day%\%Folder%

Set Folder=folder4
robocopy /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:c:\outputfolder\%day%Log.txt /NFL /NDL  \\fileserver\%Folder%  c:\outputfolder\%day%\%Folder%


Rem      You can also use this parameter if you want to do month end or year end jobs--just do If dt == ??? then
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do Set dt=%%i%%l%%j%%k
thanks lionelmm....
that shows me a new way of doing a few things, wth the dates/months etc....
It's not really the solution i was looking for on this particular question, but will be helpful in the future possibly.

I don't think the 'actual' solution i was thinking of is possible....which was to have multiple Source directories, and multiple destination directories in a .rcj  job file for robocopy.

oBdA's solution will acomplish my ulitmate goal for my backup I am awarding points based on that.

Thanks to all !!