Robocopy

When you want to copy a file from one location to another with reliable and with logging, robocopy might just be the tool for you.

See Robocopy

I will post an example which you can modify yourself to suit your needs:

Set server=%1

Rem ===================================================================================================
Rem "Check if server is reachable"
Rem ===================================================================================================

ping %server% |find /N /I "Reply"
if %errorlevel% equ 0 (
        goto :Copy
    ) Else (
        Echo %server% >>.\Log\ServerDown.txt
    ) 

goto :EOF

Rem ===================================================================================================
Rem "Copy Files to reachable server and log Succes/Failed
Rem ===================================================================================================

:Copy
robocopy  "Z:\Folder\path_to\FolderWithData" \\%server%\D$\temp *.* /copy:dat /z /w:5 /r:5 /log+:.\Log\Copy.log
if %errorlevel% GTR 1 (
            Echo %server% %errorlevel% >>.\Log\CopyFailed.txt
               ) Else (
            Echo %server% >>.\Log\CopySuccess.txt
        )

goto :EOF

You will need to adjust this code and paste it into a batchfile e.g testSP2.cmd

Next you will need another batchfile with the following code:

for /f %%i in (Servers.txt) do call testSP2.cmd %%i%

Save this as startcopy.cmd

You also need a file with servernames called servers.txt

To simple mirror 2 directories type

robocopy c:\download\music f:\download\mijn_muziek /MIR

Keep in mind that this will delete files in the destination if there are already file in because it will MIRROR the directories one way from source to destination so source is leading
To copy files from c:\ to f:\ and leave the files in the destination type
robocopy c:\download\music f:\download\mijn_muziek /E

There is also a neat way in powershell to get the benefit from robocopy AND powershell. Check out the next cool script from www.powershell.com
robocopy $env:windir\ c:\logfiles\ *.log /R:0 /LEV:3 /S /XD *winsxs*  | 
Where-Object { $_} | 
Foreach-Object { 
Write-Progress "Robocopy is looking for LOG-files in:" $_.Split([char]9)[-1] 
}

$files = dir c:\logfiles *.log -Recurse

$files | Move-Item -Destination c:\logfiles\ -Force
dir c:\logfiles | Where-Object { $_.psiscontainer } | del -Recurse -Force

Another way is to move e.g. a homeshare of a user to a new fileshare:
robocopy \\oldservername\sharename \\newservername\sharename *.* /R:10 /W:10 /E /Z /COPYALL /TEE /LOG:robo_username.log
pause

On Me

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License