robocopy 是一款制作完整/增量副本的出色工具,我喜欢用它来备份。有一件事我还没搞清楚:如何具体处理 Delta 文件
情况: 来源 A正在复制到目的地 B. 使用开关 /MIR 或至少使用 /E
例子
robocopy “E:\A” “\\服务器名称\e$\B” /E /B /R:1 /W:1 /Copyall
通常情况下,只复制差异文件(Delta)。
那么,如果我想编写脚本将新复制的文件压缩到存档中以用于其他用途,该怎么办?或者如果我想将它们移动/复制到位置 D ?
所以我认为,剧本中第三个地点会很好
robocopy 源 A ;将其与源 B 匹配,然后将 Delta 复制到脚本中的位置 D,然后我们就可以压缩它
我唯一能想到的就是设置存档位或检查时间戳,但在我看来这不是一个非常可靠的解决方案
可以使用 robocopy 或脚本来处理这个问题吗?
答案1
您可以使用这样的批处理脚本,只需根据自己的需要更改变量值即可:
@echo off
:: This line asks for admin permission since the robocopy /b /copyall requires admin permission
net session >nul 2>&1 || (powershell start -verb runas '"%~0"' &exit /b)
:: Put Source Folder here
set Source=W:\md\Musicas
:: Put Comparison Folder here:
set Comparison=%userprofile%\desktop\Comparison
:: Put Destination of Delta Files Here:
set DeltaFiles=%userprofile%\desktop\Delta
:: Put the path to the log file here
set LogFile=%userprofile%\desktop\Filelist.txt
:: Put the path to command line 7zip version here:
set seven=C:\Program Files\CLI\7zip\7za.exe
:: This graps the files that exist in the original folders but don't exist in the comparision folder and saves them in the logfile
robocopy "%Source%" "%Comparison%" /L /NJH /NJS /NC /NS /NDL /E /R:1 /W:1 /Log:"%LogFile%"
:: This copies the files in the logfile to the delta folder:
For /f "usebackq tokens=*" %%a in ("%LogFile%") do Robocopy "%Source%" "%DeltaFiles%" "%%~nxa" /B /ndl /copyall /s /NJS /NJH /R:1 /w:1
:: This uses 7zip to put the delta folder into a zip file and delete the Delta folder (if you don't want to delete remove -sdel)
"%seven%" a -tzip -r -sdel "%~dp0delta.zip" "%DeltaFiles%"
:: As an Alternative you could use powershell instead of 7zip to create the zip file:
::Powershell Compress-Archive -Path "%DeltaFiles%" -DestinationPath "%DeltaFiles%\Delta.zip"
exit