Copying files from copy Server A to network share via command line - RoboCopy - command-line

I'm trying to copy files from one directory on a server to another server without overwriting permissions at the destination but I'm working with an "interesting" setup:
Server A
Git Server
Jenkins CLI
Server B
Web Server
I have a Jenkins process that will run when my fellow web developers commit changes to our repository. Jenkins then copies the files from the repository into it's workspace (located on the C: drive of the server). Once done downloading the files, I'm executing a command script that uses "ROBOCOPY" to copy the files from a directory in the Jenkins workspace to a network share (located on another server) that is pointed to the IIS web directory.
The ROBOCOPY script is as follows:
ROBOCOPY "C:\...\Jenkins\workspace\dev\app" "\\network-share-to-web-server\app" /mir /m /R:0 /W:1 /MT:8 /V /LOG:WhySkip.txt & if %errorlevel% leq 2 exit 0
Here's the problem: ROBOCOPY will only copy the directory structure and NOT the files within the directories which is all of our HTML/JavaScript/CSS/Images... AKA: The changes that we've done.
Any and all help would be greatly appreciated!

Try without /m (Copy only files with the Archive attribute and reset it)
As you want /MIR (Mirror), let Robocopy choose files to sync

Related

Robocopy with logs

I want to use robocopy for one copying work where whole directory and it's subdirectories with files needs to be copied, but also the log files must contains the logs of copied as well skipped files details. I was using below command robocopy src dest /e /logs:dest
But it's not working for me, can anyone please suggest the required command that can be used for this purpose. Thanks.

Robocopy Error 3 "System cannot find the file specified" for 1 file in the folder

I am trying to copy a folder from the network path to my machine .But while copying the folder the robocopy suddenly got stuck in copying 1 file from the folder and did not proceed forward . I am seeing the error ERROR 3 (0x00000003) , "The System cannot find the path specified." , even though the file did exist in the source directory.
The command that I use is
ROBOCOPY source destination /MIR /Z /Log+:logs.txt
I am seeing this issue when my executable is triggered by the task scheduler. This issue does not happen when i run the exe directly. Any idea why this could be happening and also how to fix this problem
When robocopy claims it cannot find a file, it often means it is running into permission issues. If your script works from the command line, but not from the task scheduler, make sure the task uses your user credentials. You can set them in the task properties on the general tab under security options.

RoboCopy Copy To another server in same domain

I would like to copy/duplicate folder data from ServerA to ServerB in same domain (Server PRD to DRC)
For Example:
Source Folder A on server 10.192.10.1
C :\Folder A
Destination Folder B on server 10.194.10.1
C :\Folder B
Run on domain : corp
How can I write a batch script to achieve this?
Something like this would do the trick:
#echo off
REM Filename: sync-dirs.bat
REM generic robocopy backup script that DELETES (purge) files on the
REM Destination if they are also deleted on the Source! (i.e. sync/mirror).
set ROBOCOPY=c:\windows\system32\robocopy.exe
set SRC=\\10.192.10.1\shared_folder_A
set DST=\\10.194.10.1\shared_folder_B
%ROBOCOPY% %SRC% %DST% /MIR /R:10 /W:1 /ETA
Hope this helps..

How to exclude subdirectories in the destination while using /mir /xd switch in robocopy

There is a script running which mirrors a bunch of folders from one volume to another. The problem is that now there are going to be subdirectories within those folders at the destination which are not part of the original mirroring script. They are standalone subdirectories and I don't want them purged once the mirroring kicks in. Is there a way for me to use the /xd switch in robocopy wherein I'd be able to exclude the destination subdirectories.
Example:
robocopy "\\hq04t2fis202\archive\dr" "\\hq04t3fis202\archive\dr" /mir /xd "\\hq04t3fis202\archive\dr\*\hq04s2dba301"
In the above example, there are several directories under \\hq04t2fis202\archive\dr that are being mirrored. And at the destination, once these directories are mirrored from the source, there is another script which dumps separate subdirectories within each of those directories. So what I want to do is somehow use the /xd switch to avoid purging those subdirectories at the destination.
Also, in the above example, in the /xd switch, I'm using the "*" wildcard to mean that I want to include all the directories that fall under the "\\hq04t3fis202\archive\dr" root folder at the destination.
Need help and suggestions as to whether this is possible, and if it is then how can I do it. So far I've tried and tested many other switches like /xo, /xx, but none of them solve my purpose.
Also, /xx would work except that now it won't delete any folders at the destination at all and it wouldn't be mirroring.
Hopefully I'm not overly confusing everyone here. Let me know if you have any questions.
When i tried the solution with /XD i found, that the path to exclude should be the source path - not the destination.
e.g. this Works
robocopy c:\test\a c:\test\b /MIR /XD c:\test\a\leavethisdiralone\
Rather than creating empty directories in source to exclude, you can supply the full destination path to the /XD switch to have the destination directories untouched
robocopy "%SOURCE_PATH%" "%DEST_PATH%" /MIR /XD "%DEST_PATH%"\hq04s2dba301
The issue is that even though we add a folder to skip list it will be deleted if it does not exist.
The solution is to add both the destination and the source folder with full path.
I will try to explain the different scenarios and what happens below, based on my experience.
Starting folder structure:
d:\Temp\source\1.txt
d:\Temp\source\2\2.txt
Command:
robocopy D:\Temp\source D:\Temp\dest /MIR
This will copy over all the files and folders that are missing and deletes all the files and folders that cannot be found in the source
Let's add a new folder and then add it to the command to skip it.
New structure:
d:\Temp\source\1.txt
d:\Temp\source\2\2.txt
d:\Temp\source\3\3.txt
Command:
robocopy D:\Temp\source D:\Temp\dest /MIR /XD "D:\Temp\source\3"
If I add /XD with the source folder and run the command it all seems good the command it wont copy it over.
Now add a folder to the destination to get this setup:
d:\Temp\source\1.txt
d:\Temp\source\2\2.txt
d:\Temp\source\3\3.txt
d:\Temp\dest\1.txt
d:\Temp\dest\2\2.txt
d:\Temp\dest\3\4.txt
If I run the command it is still fine, 4.txt stays there 3.txt is not copied over. All is fine.
But, if I delete the source folder "d:\Temp\source\3" then the destination folder and the file are deleted even though it is on the skip list
1 D:\Temp\source\
*EXTRA Dir -1 D:\Temp\dest\3\
*EXTRA File 4 4.txt
1 D:\Temp\source\2\
If I change the command to skip the destination folder instead then the folder is not deleted, when the folder is missing from the source.
robocopy D:\Temp\source D:\Temp\dest /MIR /XD "D:\Temp\dest\3"
On the other hand if the folder exists and there are files it will copy them over and delete them:
1 D:\Temp\source\3\
*EXTRA File 4 4.txt
100% New File 4 3.txt
To make sure the folder is always skipped and no files are copied over even if the source or destination folder is missing we have to add both to the skip list:
robocopy D:\Temp\source D:\Temp\dest /MIR /XD "d:\Temp\source\3" "D:\Temp\dest\3"
After this no matters if the source folder is missing or the destination folder is missing, robocopy will leave it as it is.
The way you can exclude a destination directory while using the /mir is by making sure the destination directory also exists on the source. I went into my source drive and created blank directories with the same name as on the destination, and then added that directory name to the /xd. It successfully mirrored everything while excluding the directory on the source, thereby leaving the directory on the destination intact.
The argument order seems to matter... to exclude subdirectories, I used
robocopy \\source\folder C:\destinationfolder /XD * /MIR
...and that works for me (Windows 10 copy from Windows Server 2016)
Try my way :
robocopy.exe "Desktop\Test folder 1" "Desktop\Test folder 2" /XD "C:\Users\Steve\Desktop\Test folder 2\XXX dont touch" /MIR
Had to put /XD before /MIR while including the full Destination Source directly after /XD.

After Robocopy, the copied Directory and Files are not visible on the destination Drive

I've been happily using robocopy for backing up my computers to an external usb drive. It's great since it only copies the files that were changed/updated/new. I can take my external drive to any machine and look at it just as if it's another drive on the computer.
I've recently purchased a 750g and another 1tb external hard drives. I ran a robocopy over the weekend that copied about 500g to my external drive. After the copy My Computer shows that ~500g has been used on the external drive. The strange thing is that when I click on the drive in Windows Explorer, nothing shows up in the right pane of Windows Explorer (and the + goes away in the left pane). I copied a single file (drag-and-drop) to this drive and it shows up in Windows Explorer. Command Prompt show the same thing. 1 file.
I know the files are on the drive as it shows up as the Free Space has been reduced.
I read that I should make sure simple file sharing is off, which it is. I also took ownership of the files as Administrator. Still nothing. It works the same on my WIndows XP machine and my Windows 7 Ultimate.
Has anyone else seen this? Or even better, does anyone know what I am doing wrong or how to solve this problem?
thanks!
Bill44077
In my case, the above didn't work.
This worked instead: attrib -h -s -a [ Drive : ][ Path ].
For example: attrib -h -s -a "C:\My hidden folder".
When copying from the root directory of a drive to a folder (non-root directory on a different drive), this can happen.
RoboCopy may set the new directory to hidden, as it copies the system attribute of the root folder of the drive over to the new folder.
You can prevent the new directory from becoming hidden by adding the /A-:SH option/flag/switch to your robocopy command.
See this Server Fault Answer to "Why does RoboCopy create a hidden system folder?
" for more information.
However, this may or may not prevent copying system attributes in other folders, according to this discussion on the Microsoft forum "ROBOCOPY hides destination Directory".
Here is an example taken from my longer, more thorough, Answer on Super User to the Question "How to preserve file attributes when one copies files in Windows?":
Robocopy D:\ C:\D_backup /A-:SH /DCOPY:T /COPYALL /E /R:0 /ZB /ETA /TEE /V /FP /XD D:\$RECYCLE.BIN /XD "D:\System Volume Information" /LOG:C:\D_backup_robocopy.LOG /MIR
However, if you already copied the directory without the /A-:SH option, running the command mentioned by Ricky above (attrib -h -s -a [ Drive : ][ Path ]) will fix the issue by unhiding the directory. Though, I found that -a was not needed.
So in my case, for the example above, attrib -h -s C:\D_backup (without the -a option) made D_backup visible.
Just ran into this issue myself, so it may be a late response and you may have worked it out already, but for those stumbling on this page here's my solution...
The problem is that for whatever reason, Robocopy has marked the directory with the System Attribute of hidden, making it invisible in the directory structure, unless you enable the viewing of system files.
The easiest way to resolve this is through the command line.
Open a command prompt and change the focus to the drive in question (e.g. x:)
Then use the command dir /A:S to display all directories with the System attribute set.
Locate your directory name and then enter the command ATTRIB -R -S x:\MyBackup /S /D where x:\ is the drive letter and MyBackup is your directory name.
The /S re-curses subfolders and /D processes folders as well.
This should clear the Read Only and System attributes on all directories and files, allowing you to view the directory normally.
In addition to the great answers SherylHohman and Ricky left I wanted to add that merely adding the /A-:SH switch for robocopy did not work and the copy created a hidden, system folder on the destination drive.
However, using the /A-:SHA parameter did work and my top level destination directory was not given the system or hidden attributes. Weirdly, my drive does not have the "a" (archived) attribute set so I am dumbfounded as to why this works at all. I do prefer simply removing these attributes to only the root destination folder after completion of the robocopy command per Ricky's suggestion so that these attributes are respected for any sub-directories. Though the /A- switch is easier to manage and (for my backup purposes) are not relevant to any directories I am backing up. You may want to consider not removing the system or hidden attributes if you're backing up your C:\ drive though.
You could try this, I say could, because the whole Windows 10 has annoying flaws everywhere, I have lost trust to Windows 10 and Microsoft.
Well I found that after I robocopied the whole Documents-folder to a root of external drive, I got a folder that is not named Documents but the Documents-folder is renamed&translated to my native language, so it could be some Language issue. (the /XD option tells robocopy to skip a folder)
C:\users\asdf\documents >robocopy . f:\ManuBackup /XD c:\Users\Asdf\Documents\OneDrive /s
File Explorer shows Tiedostot-name (=Documents in finnish) and Command Prompt shows ManuBackup-name. Also I have tried all attrib.exe commands to the ManuBackup-folder, don't trust me 100%