Shortik
Shortik

Reputation: 175

Robocopy - exclude a lot of directories

I have problem with robocopy. I want to use it for backing up a system disc and I want to exclude some system folders. But it's still trying to copy some of these folders. My batch file is this:

robocopy c:\ l:\C\ /r:1 /w:1 /mir /dcopy:T /xjd /xjf /xj /copy:DT /log+: l:\RobocopyLogC.txt /xf "desktop.ini" /xd "$Recycle.Bin" /xd Config.Msi /xd MSOCache/xd Recovery /xd "System Volume Information" /xd Windows /xd "Program Files\Common Files" /xd "Program Files\Internet Explorer" /xd "Program Files\Reference Assemblies" /xd "Program Files\Uninstall Information" /xd "Program Files\Microsoft Analysis Services" /xd "Program Files\Microsoft Mouse and Keyboard Center" /xd "Program Files\Microsoft Office" /xd "Program Files\Microsoft Silverlight" /xd "Program Files\MSBuild" /xd "Program Files\Windows Defender" /xd "Program Files\Windows Journal" /xd "Program Files\Windows Mail" /xd "Program Files\Windows Media Player" /xd "Program Files\Windows Multimedia Platform" /xd "Program Files\Windows NT" /xd "Program Files\Windows Photo Viewer" /xd "Program Files\Windows Portable Devices" /xd "Program Files\Windows Sidebar" /xd "Program Files\WindowsApps" /xd "Program Files\WindowsPowerShell" /xd "Program Files (x86)\Common Files" /xd "Program Files (x86)\InstallShield Installation Information" /xd "Program Files (x86)\Internet Explorer" /xd "Program Files (x86)\Microsoft Analysis Services" /xd "Program Files (x86)\Microsoft Office" /xd "Program Files (x86)\Microsoft Silverlight" /xd "Program Files (x86)\Microsoft.NET" /xd "Program Files (x86)\MSBuild" /xd "Program Files (x86)\Reference Assemblies" /xd "Program Files (x86)\Temp" /xd "Program Files (x86)\Windows Defender" /xd "Program Files (x86)\Windows Mail" /xd "Program Files (x86)\Windows Media Player" /xd "Program Files (x86)\Windows Multimedia Platform" /xd "Program Files (x86)\Windows NT" /xd "Program Files (x86)\Windows Photo Viewer" /xd "Program Files (x86)\Windows Portable Devices" /xd "Program Files (x86)\WindowsPowerShell" /xd "Program Files (x86)\Windows Sidebar" /xd ProgramData\Microsoft /xd "ProgramData\Microsoft Help" /xd "ProgramData\Package Cache" /xd Users\Public /xd Users\Default /xd Users\userName2 /xd Users\userName\AppData\LocalLow\Temp /xd Users\userName\AppData\Local\Temp

I have tried a lot of things, but nothing helped. Can you help me?

Upvotes: 15

Views: 77407

Answers (4)

Piotr Napora
Piotr Napora

Reputation: 31

In the paths replace the double quotes symbol (ex. "C:\$Recycle.Bin") with a single quote symbol ('C:\$Recycle.Bin'). This is because the dollar character "$" starts the variable and is interpreted as a variable named "$Recycle".

Upvotes: 3

Charlie C
Charlie C

Reputation: 11

My solution for this was to create .txt files that contain the files or directories I want to include or exclude. I have these files in a subfolder "rcXcludes" under my "Backup" folder. My method for naming the files is as follows. I preface them with "rc" (for robocopy), then some recognizable notation for the application or part of the file system in the robocopy command, then append "B" or "R" (for Backup or Restore), then "I" or "X" (for Include or Exclude), then "D" or "F" (for Directory or File). I surround each entry with double quotes and a space between entries. An "Include" file can have files or directories, but directories must have a trailing backslash. In an "Exclude" file for directories you do not use a trailing backslash. Any directory entries are relative to the source path in the robocopy command. The entire contents of any of these .txt files must be on one line and not have a carraige return line feed. In my batch file, I use a SET /P command to import the .txt file into a variable. I then use these variables for FILES or after /XF or /XD. For instance, to backup the current user's Chrome profile without copying the entire "Default" folder, I use the following.

rcChromeBIF.txt  
"Bookmarks" "Custom Dictionary.txt" "Extension Cookies" "Favicons" "History" "Login Data" "Preferences" "Top Sites" "Visited Links" "Web Data" "Databases\" "Extensions\" "Local Storage\" "Plugin Data\" "User Scripts\" "User StyleSheets\"

rcChromeBXF.txt  
"Bookmarks.bak" "ChromeDWriteFontCache" "Cookies" "Cookies-journal" "Current Session" "Current Tabs" "Extension Cookies-journal" "Favicons-journal" "Google Profile.ico" "History Provider Cache" "History-journal" "Last Session" "Last Tabs" "Login Data-journal" "Network Action Predictor" "Network Action Predictor-journal" "Network Persistent State" "Origin Bound Certs" "Origin Bound Certs-journal" "QuotaManager" "QuotaManager-journal" "README" "Secure Preferences" "Shortcuts" "Shortcuts-journal" "Top Sites-journal" "TransportSecurity" "Web Data-journal"

rcChromeBXD.txt  
"Application Cache" "Cache" "data_reduction_proxy_leveldb" "Extension State" "File System" "GPUCache" "IndexedDB" "JumpListIcons" "JumpListIconsOld" "Local Extension Settings" "Media Cache" "Pepper Data" "Platform Notifications" "Service Worker" "Session Storage" "Storage" "Thumbnails" "Web Applications"

In the bat file in, say, C:\Backup.

REM ChromeBak.bat
SET chromeprofdir=Google\Chrome\User Data\Default
SET /P rcChrmBIF=<C:\Backup\rcXcludes\rcChromeBIF.txt
SET /P rcChrmBXF=<C:\Backup\rcXcludes\rcChromeBXF.txt
SET /P rcChrmBXD=<C:\Backup\rcXcludes\rcChromeBXD.txt
robocopy "%LOCALAPPDATA%\%chromeprofdir%" "H:\ChromeBackup\%chromeprofdir%" %rcChrmBIF% /E /ZB /COPY:DAT /DCOPY:T /MT:4 /XJ /XF %rcChrmBXF% /XD %rcChrmBXD% /R:10 /W:2 /TBD /NP /V /TS /Log+:"H:\ChromeBackup\ChromeBackup.log"

Upvotes: 1

Harry Johnston
Harry Johnston

Reputation: 36308

The /xd option does not appear to work well with relative paths. Try using absolute paths instead, e.g.,

robocopy c:\ l:\C\ /r:1 /w:1 /mir /dcopy:T /xjd /xjf /xj /copy:DT ... 
   /xd "C:\$Recycle.Bin" 
   /xd C:\Config.Msi 
   /xd C:\MSOCache
   /xd C:\Recovery 
   /xd "C:\System Volume Information" 

(Split for readability.)

Upvotes: 8

Phab
Phab

Reputation: 495

Dont use multiple /xd! Just set all the directories behind the first /xd

... /xd "dir1" "dir2" "dir3" ...

Upvotes: 33

Related Questions