命令行 使用 RoboCopy 进行 3 天滚动备份



我想完成的是源文件夹的三天滚动备份,该备份将每天修改。我希望删除超过 3 天的任何内容,因为最坏的情况我将不得不恢复到最新的备份,但如果需要,拥有 3 天允许我恢复到以前的更改。

我在命令行中所做的如下:

SET STAMP=%DATE:/=-% %TIME::=.%
SET SOURCE="C:UsersPersonADocumentsTestSource"
SET DEST="C:UsersPersonADocumentsTestDestination%STAMP%"
robocopy %SOURCE% %DEST% /e
forfiles -p "C:UsersPersonADocumentsTestDestination" -s -m *.* -d -3 -c "cmd /c echo @file"

我已经为文件夹名称以及当前日期和时间加盖了时间戳并连接起来。

然而,我正在努力让他删除任何超过 3 天的内容,目前该过程只是复制,但我需要一个过程来检测修改日期或可能创建的日期并使用我生成的代码删除超过 3 天的目录。我在上面添加的已删除命令似乎根本没有做任何事情。

如果有人能帮忙,我将不胜感激。

提前谢谢你

我会推荐这样的东西:

SET STAMP=%DATE:/=-% %TIME::=.%
SET SOURCE="C:UsersPersonADocumentsTestSource"
SET DEST="C:UsersPersonADocumentsTestDestination%STAMP%"
REM Set Robocopy to only retry once after waiting 1 second; copy all
REM file attributes, security, etc; and create a log file in the 
REM temp folder with the same name as the date.
robocopy %SOURCE% %DEST% /e /r:1 /w:1 /COPYALL /LOG:%TEMP%%STAMP%.LOG
C:
CD UsersPersonADocumentsTestDestination
REM Recursively and quietly delete all directories older than
REM 3 days
FORFILES /S /D -3 /C "cmd /c IF @isdir == TRUE rd /S /Q @path"

这是从这篇文章中给出的答案推断出来的。

最新更新