我遇到了robocopy的问题。我想用它来备份系统光盘,我想排除一些系统文件夹。但它仍在尝试复制其中一些文件夹。 我的批处理文件是:
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
我尝试了很多东西,但没有任何帮助。你能救我吗?
答案 0 :(得分:13)
不要使用multiple / xd! 只需设置第一个/ xd
后面的所有目录... /xd "dir1" "dir2" "dir3" ...
答案 1 :(得分:2)
/xd
选项似乎不适用于相对路径。请尝试使用绝对路径,例如,
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"
(为了便于阅读而拆分。)
答案 2 :(得分:2)
在路径中,将双引号(例如“ C:\ $ Recycle.Bin”)替换为单引号('C:\ $ Recycle.Bin')。这是因为美元字符“ $”开始变量,并被解释为名为“ $ Recycle”的变量。
答案 3 :(得分:0)
我的解决方案是创建包含我想要包含或排除的文件或目录的.txt文件。我将这些文件放在我的“备份”文件夹下的子文件夹“rcXcludes”中。我命名文件的方法如下。我在前面加上“rc”(用于robocopy),然后在robocopy命令中为应用程序或部分文件系统添加一些可识别的符号,然后附加“B”或“R”(用于备份或恢复),然后“I”或“X”(包含或排除),然后是“D”或“F”(用于目录或文件)。我用双引号和条目之间的空格包围每个条目。 “Include”文件可以包含文件或目录,但目录必须具有尾部反斜杠。在目录的“排除”文件中,不使用尾部反斜杠。任何目录条目都相对于robocopy命令中的源路径。任何这些.txt文件的全部内容必须在一行上,不具有carraige返回换行符。 在我的批处理文件中,我使用SET / P命令将.txt文件导入变量。然后我将这些变量用于FILES或/ XF或/ XD之后。 例如,要备份当前用户的Chrome配置文件而不复制整个“默认”文件夹,我使用以下内容。
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"
在bat文件中,例如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"