删除 Robocopy 备份是否安全?我读到有些人不小心删除了备份之外的文件,因为它包含链接/连接。我可以防止这种情况吗?
该的Robocopy文档控制的Robocopy的有关文件系统的链接行为列表选项:
/sl 不要遵循符号链接,而是创建链接的副本。
/xj 排除连接点,默认情况下通常包含这些连接点。
/xjd 排除目录的连接点。
/xjf 排除文件的连接点。
我创建了一个批处理脚本来了解 Robocopy 在使用和不使用这些选项的情况下如何工作。它使用mlink
. 使用mlink
,您可以创建:
符号链接可以是相对的或绝对的,这取决于您传递目标参数的方式。硬链接和连接点始终是绝对的,即使您传递了一个相对目标。
@echo off
set home=C:\my-directory
cd %home%
mkdir robocopy-source
cd robocopy-source
mkdir a
mkdir b
copy NUL b\foo.txt
cd a
mklink /j junction-dir-absolute %home%\robocopy-source\b\
mklink /d symlink-dir-absolute %home%\robocopy-source\b\
mklink /d symlink-dir-relative ..\b\
mklink /h hardlink-file-absolute %home%\robocopy-source\b\foo.txt
mklink symlink-file-absolute %home%\robocopy-source\b\foo.txt
mklink symlink-file-relative ..\b\foo.txt
cd %home%
robocopy robocopy-source robocopy-target /mir /dcopy:dat
robocopy robocopy-source robocopy-target-sl /mir /dcopy:dat /sl
robocopy robocopy-source robocopy-target-xj /mir /dcopy:dat /xj
robocopy robocopy-source robocopy-target-xjd /mir /dcopy:dat /xjd
robocopy robocopy-source robocopy-target-xjf /mir /dcopy:dat /xjf
使用Link Shell Extension,我们现在可以看到发生了什么:
小路 | 信息 |
---|---|
robocopy-source\a\junction-dir-absolute | %home%\robocopy-source\b\ 的链接 |
robocopy-source\a\symlink-dir-absolute | %home%\robocopy-source\b\ 的链接 |
robocopy-source\a\symlink-dir-relative | 链接到 ..\b\ |
robocopy-source\a\hardlink-file-absolute | %home%\robocopy-source\b\foo.txt 的链接(和它本身) |
robocopy-source\a\symlink-file-absolute | 链接到 C:\Users\Marco\Desktop\Linktest\robocopy-source\b\foo.txt |
robocopy-source\a\symlink-file-relative | ..\b\foo.txt 的链接 |
robocopy-target\a\junction-dir-absolute | 复制内容为 %home%\robocopy-source\b\ 的目录 |
robocopy-target\a\symlink-dir-absolute | 复制内容为 %home%\robocopy-source\b\ 的目录 |
robocopy-target\a\symlink-dir-relative | 复制内容为 %home%\robocopy-source\b\ 的目录 |
robocopy-target\a\hardlink-file-absolute | 空的文件 |
robocopy-target\a\symlink-file-absolute | 空的文件 |
robocopy-target\a\symlink-file-relative | 空的文件 |
robocopy-target-sl\a\junction-dir-absolute | 复制内容为 %home%\robocopy-source\b\ 的目录 |
robocopy-target-sl\a\symlink-dir-absolute | %home%\robocopy-source\b\ 的链接 |
robocopy-target-sl\a\symlink-dir-relative | 链接到 ..\b\ |
robocopy-target-sl\a\hardlink-file-absolute | 空的文件 |
robocopy-target-sl\a\symlink-file-absolute | %home%\robocopy-source\b\foo.txt 的链接 |
robocopy-target-sl\a\symlink-file-relative | ..\b\foo.txt 的链接 |
robocopy-target-xj\a\junction-dir-absolute | 不存在 |
robocopy-target-xj\a\symlink-dir-absolute | 不存在 |
robocopy-target-xj\a\symlink-dir-relative | 不存在 |
robocopy-target-xj\a\hardlink-file-absolute | 空的文件 |
robocopy-目标-xj\a\symlink-file-absolute | 不存在 |
robocopy-target-xj\a\symlink-file-relative | 不存在 |
robocopy-target-xjd\a\junction-dir-absolute | 不存在 |
robocopy-target-xjd\a\symlink-dir-absolute | 不存在 |
robocopy-target-xjd\a\symlink-dir-relative | 不存在 |
robocopy-target-xjd\a\hardlink-file-absolute | 空的文件 |
robocopy-target-xjd\a\symlink-file-absolute | 空的文件 |
robocopy-target-xjd\a\symlink-file-relative | 空的文件 |
robocopy-target-xjf\a\junction-dir-absolute | 复制内容为 %home%\robocopy-source\b\ 的目录 |
robocopy-target-xjf\a\symlink-dir-absolute | 复制内容为 %home%\robocopy-source\b\ 的目录 |
robocopy-target-xjf\a\symlink-dir-relative | 复制内容为 %home%\robocopy-source\b\ 的目录 |
robocopy-target-xjf\a\hardlink-file-absolute | 空的文件 |
robocopy-target-xjf\a\symlink-file-absolute | Does not exist |
robocopy-target-xjf\a\symlink-file-relative | Does not exist |
I conclude that unless you have used the /sl
option, deleting a backup created with Robocopy should be safe. If you did use the /sl
option however, absolute symbolic links could get you into trouble, e.g. when using the del
command.
Further observations:
/xjd
skips links to directories. Other than the docs imply, it does not only skip junctions, but also symbolic links!/xjf
skips links to files. Other than the docs imply, it does not skip junctions for files (which do not exist anyway), but symbolic links!/xj
combines /xjd
and /xjf
.I have reported the issue with the docs.
Bonus info regarding shortcuts (.lnk files)
Shortcuts are treated by Robocopy like regular files, so they will generally point outside of your backup directory. However, they are usually treated like regular files by other command line programs, too. I have checked this for del /s /q
and rmdir /s /q
in the command prompt and rm -rf
in the MINGW64 shell, all of which will not follow the shortcuts and thus will not lead to unintended deletions.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句