Solved

Robocopy job file question

Posted on 2011-02-14
23
2,754 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:SeaSenor
  • 10
  • 8
  • 5
23 Comments
 
LVL 83

Expert Comment

by:oBdA
ID: 34894869
What exactly is it that you want to do? What you listed above is not valid robocopy syntax.
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 34896629
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
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 34896645
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
::
:: Robocopy Job T:\BACKUP\JOBS\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.
0
 
LVL 8

Author Comment

by:SeaSenor
ID: 34897299
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 is....is 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?

 
0
 
LVL 83

Expert Comment

by:oBdA
ID: 34897366
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

0
 
LVL 8

Author Comment

by:SeaSenor
ID: 34897439
would i have to do it to each and every .bat file?
0
 
LVL 8

Author Comment

by:SeaSenor
ID: 34898042
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 :)
0
 
LVL 83

Expert Comment

by:oBdA
ID: 34898696
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.
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 34898797
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.
0
 
LVL 8

Author Comment

by:SeaSenor
ID: 34899027
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 script....is that not the closer?
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 34899352
The script in http:#a34897366 is the one that's not working; the second one should be correct.
Anyway, here's a version with the day defined in the script, and the folders to copy are listed in a text file "FolderList.txt" in the same folder as the script.
FolderList.txt:
Folder1
Folder2
Folder3
Folder4

Open in new window

And the script:
set day=Monday
set FolderFile=%~dp0FolderList.txt
if exist "c:\outputfolder\%day%Log.txt" del "c:\outputfolder\%day%Log.txt"
for /f "delims=" %%a in ('type "%FolderFile%"') 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

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 24

Expert Comment

by:lionelmm
ID: 34899435
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!
0
 
LVL 8

Author Comment

by:SeaSenor
ID: 34900283
oBbA........
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?

0
 
LVL 8

Author Comment

by:SeaSenor
ID: 34900299
Lionelmm -

i would love to see the batch file....it wouldn't be a waste of time at all.
Please write it if you don't mind doing so.
0
 
LVL 83

Expert Comment

by:oBdA
ID: 34900365
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
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 34901320
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
0
 
LVL 8

Author Comment

by:SeaSenor
ID: 34901454
lionelmm -
if you mean run it in a cmd window I did...

was unexpected at this time.






















0
 
LVL 24

Expert Comment

by:lionelmm
ID: 34901479
no sorry you would have to run it from a batch file--sorry my bad
0
 
LVL 8

Author Comment

by:SeaSenor
ID: 34901617
set day=Tue
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 34907002
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.
0
 
LVL 8

Author Comment

by:SeaSenor
ID: 34907761
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.
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 34908099
@Echo on
Rem      Batch File to run RoboCopy to Folder from Server
Rem      Created on 2011-02-16

:Start
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%

:End

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
0
 
LVL 8

Author Closing Comment

by:SeaSenor
ID: 34908342
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 set....so I am awarding points based on that.

Thanks to all !!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Windows 10 is here and for most admins this means frustration and challenges getting that first working Windows 10 image. As in my previous sysprep articles, I've put together a simple help guide to get you through this process. The aim is to achiev…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now