Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 879
Umang M Avatar asked Jan 24 '13 21:01

Umang M


People also ask

Does Robocopy copy subdirectories?

The most basic use of robocopy is using a source and destination directory with no options. This option will copy all files (excluding subfolders) from C:\src to C:\dst. You can also copy everything including subfolders (empty or not) and NTFS permissions.

How do I exclude a hidden folder in Robocopy?

You can try to use the /XD parameter in order to exclude a directory based on a pattern. I've found that using /XD *. excludes directories with dots. I combine it with XA:SH in order to also exclude hidden files.

What is Mir switch in Robocopy?

/MIR is an option to ROBOCOPY where you mirror a directory tree with all the subfolders including the empty directories and you purge files and folders on the destination server that no longer exists in source.


2 Answers

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\ 
like image 184
Lars Meldgård Avatar answered Sep 28 '22 01:09

Lars Meldgård


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 
like image 38
psaxton Avatar answered Sep 28 '22 03:09

psaxton