windows 运行 robocopy bat 将整个驱动器复制到另一个驱动器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23302049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
run robocopy bat to copy entire drive to another drive
提问by cherrytree
I'm trying to run a simple backup (mirror) of one entire drive (d:) to another drive (k:). I've created a .bat file ('backup.bat') defining the source (d:) and destination (k:) and placed this batch file within a folder on the d drive (d:\temp). When I double-click on the batch file it defines the source as d:\temp, instead of what I've defined it as in the batch file; d:.
我正在尝试将整个驱动器 (d:) 的简单备份(镜像)运行到另一个驱动器 (k:)。我创建了一个定义源 (d:) 和目标 (k:) 的 .bat 文件 ('backup.bat'),并将此批处理文件放在 d 驱动器 (d:\temp) 上的文件夹中。当我双击批处理文件时,它将源定义为 d:\temp,而不是我在批处理文件中定义的;德:。
Here is the text in the .bat file:
这是 .bat 文件中的文本:
@echo off
echo To begin backing up data:
pause
robocopy "D:" "K:" /L /v
echo.
pause
exit
And this is what shows up when I double-click on the backup.bat
这就是我双击 backup.bat 时显示的内容
As you can see, source is defined as d:\temp. This is where the batch file is located, but in the batch file I defined it as D:. For some reason, the destination is defined correctly.
如您所见,源定义为 d:\temp。这是批处理文件所在的位置,但在批处理文件中我将其定义为 D:。出于某种原因,目的地定义正确。
Any ideas?
有任何想法吗?
-al
-al
EDIT: If I add the '/' to the source and destination location, see code below, I see even more odd behavior (see screenshot). The source is now both the defined source and destination combined, w/ no destination.
编辑:如果我将“/”添加到源和目标位置,请参阅下面的代码,我会看到更多奇怪的行为(请参见屏幕截图)。源现在是定义的源和目标的组合,没有目标。
@echo off
echo To begin backing up data:
pause
robocopy "D:\" "K:\" /L /v
echo.
pause
exit
And, if I remove the "" from the source and destination....IT WORKs!
而且,如果我从源和目标中删除“”....它起作用了!
@echo off
echo To begin backing up data:
pause
robocopy D:\ K:\ /L /v
echo.
pause
exit
回答by PA.
with "D:"
you are notspecifying the rootdirectory of the D drive (D:\
) but the currentdirectory of D instead, (D:\temp
in your example).
与"D:"
你没有指定根的d盘(目录D:\
),但当前d的目录,而不是,(D:\temp
在你的例子)。
To solve this problem, just add \
to the source spec (and while there, to the dest spec as well)
要解决这个问题,只需添加\
到源规范(在那里,也添加到目标规范)
robocopy d:\ k:\ /L /v
回答by Megachip
Use the /E
Option.
Also check other necessary/useful params like /copyall
/ZB
or /DCOPY:DAT
via /?
.
使用/E
选项。还要检查其他必要/有用的参数,例如/copyall
/ZB
或/DCOPY:DAT
via /?
。
回答by thenobes
I have found that you need a space after the last slash when you put a path In quotes for the source and or destination. If you have embedded spaces, you need quotes, thus you need the space after the last slash in the path, e.g. “c:\ “ not “c:\”
我发现当您将路径放在源和/或目标的引号中时,最后一个斜杠后需要一个空格。如果你有嵌入的空格,你需要引号,因此你需要路径中最后一个斜杠后面的空格,例如“c:\”而不是“c:\”
Can't really tell you what's going on there with robocopy, but all my backup scripts take this into account.
无法真正告诉您 robocopy 发生了什么,但我所有的备份脚本都考虑到了这一点。
Good luck!
祝你好运!