In reply to jayatheertha d u.
Hi Jay,
Robocopy is “just” a program that you can launch and it will terminate when done. To relaunch it you will need a task scheduler.
From your question I can not determine how dynamic your locations are. But if you are copying from a set of folders at various times, then I would make e.g. 4 different robocopy tasks in a scheduler, each doing a specific task.
Otherwise, if your copying is very dynamic and folder names are based on for instance times, then you will have to launch ROBOCOPY from a PowerShell script or a batch shell. Use the script to set a variable with the location and then launch robocopy using the variable.
In PowerShell it will look sort of like this:
$source = YourDynamicLocation
$destination = YourOtherDynamicLocation
robocopy $source $destination -add-your-parameters-too
The specifics on the PowerShell script you will need to figure out.
–Jacob
]]>Hello Jacob,
Nice article….
I need a clarification…
I want to schedule a robocopy scheduler job for copying updates from a different location at a specified time ( for ex everyday at 3:00AM).
can I use the robocopy options and create the scheduler ( /RH option)?
If Yes, Can you please send me a sample code?
Thanks
Jay
Hello,
I have a little problem. I have a simple backup script:
———–
robocopy C:\folder1 \\network_nas\Backup\folder1 /MIR /XA:H /W:0 /R:1 /REG /FFT >> C:\users\usernameX\Desktop\externalbackup.log
————-
But in log, i see this:
2017/12/04 17:55:06 ERROR 5 (0x00000005) Creating Destination Directory \\network_nas\Backup\folder1
Access is denied.
How to set credential to destination network server ? for example username, password?
]]>All of those commands seem like an overkill. What’s wrong (if you don’t want a mirror backup–which is dangerous for networks where users delete files and then come running to the sysadmin days later that they need access to those deleted files) with something like this:
c:\robocopy.exe c:\[directory to be backed up] e:\[target directory where the files will be backed up to] /b /e /log:e:\backup_log_file.txt
ex: c:\robocopy.exe c:\home e:\ /b /e /log:e:\backup_log_file.txt
Where e:\ is the external backup drive;
c:\home is the folder to be backed up;
ymmv (your mileage may vary). . . .
P.S. Thanks for the info on scheduling. 🙂
]]>In reply to Girgoci Mihai.
I think that is not possible out of the box. You will need a folder watcher, to trigger the Robocopy script.
–Jacob
]]>In reply to Frankenstein.
Hi,
Thanks a lot it is an interesting point. I actually think about that myself. I will find a way to explain it detailed.
–Jacob
Nice guide, but you may want to let people know about the dangers of using MIR. If you effed up and used MIR against your on-going backup, your backup will be destroyed. Essentially you’ve created a guide for delayed manual “RAID-1”. They’re not backups, but “hardware” mirrors.
]]>And if you want to start the task only if I put something in the source folder ?
]]>In reply to Goulart.
Cool – and great that you share the final result 🙂
–Jacob
]]>Thank You! Now it is working like a charm! If someone need, there is the full script:
@ECHO ON
SETLOCAL
SET SourceDir=C:\test1
SET TargetDir=Z:\test2
SET tempFolderName=@_Copy_in_progress_DO_NOT_USE_@
SET LogFile=D:\LogPath\Logfile.txt
ROBOCOPY “%SourceDir%” “%SourceDir%\%tempFolderName%” /MOVE /NS /NP /v /W:0 /R:0 /LOG:%LogFile% /XD “%SourceDir%\%tempFolderName%”
:wait
TIMEOUT /t 5
ROBOCOPY “%SourceDir%\%tempFolderName%” “%TargetDir%” /MOVE /NS /NP /v /W:0 /R:0 /LOG+:%LogFile%
GOTO :EOF
:REPORT_ERRORLEVEL
echo.
if ERRORLEVEL 16 echo ***FATAL ERROR*** & goto :EOF
if ERRORLEVEL 15 echo OKCOPY + FAIL + MISMATCHES + XTRA & goto :EOF
if ERRORLEVEL 14 echo FAIL + MISMATCHES + XTRA & goto :EOF
if ERRORLEVEL 13 echo OKCOPY + FAIL + MISMATCHES & goto :EOF
if ERRORLEVEL 12 echo FAIL + MISMATCHES& goto end
if ERRORLEVEL 11 echo OKCOPY + FAIL + XTRA & goto :EOF
if ERRORLEVEL 10 echo FAIL + XTRA & goto :EOF
if ERRORLEVEL 9 echo OKCOPY + FAIL & goto :EOF
if ERRORLEVEL 8 echo FAIL & goto :EOF
if ERRORLEVEL 7 echo OKCOPY + MISMATCHES + XTRA & goto :EOF
if ERRORLEVEL 6 echo MISMATCHES + XTRA & goto :EOF
if ERRORLEVEL 5 echo OKCOPY + MISMATCHES & goto :EOF
if ERRORLEVEL 4 echo MISMATCHES & goto :EOF
if ERRORLEVEL 3 echo OKCOPY + XTRA & goto :EOF
if ERRORLEVEL 2 echo XTRA & goto :EOF
if ERRORLEVEL 1 echo OKCOPY & goto :EOF
if ERRORLEVEL 0 echo No Change & goto :EOF