batch-file - 使用 RoboCopy 的命令行 3 天滚动备份
问题描述
我想要完成的是对源文件夹进行为期三天的滚动备份,每天都会对其进行修改。我希望删除超过 3 天的任何内容,因为在最坏的情况下,我将不得不恢复到最近的备份,但是如果需要,拥有 3 天可以让我恢复到以前的更改。
我在命令行中所做的如下:
SET STAMP=%DATE:/=-% %TIME::=.%
SET SOURCE="C:\Users\PersonA\Documents\Test\Source"
SET DEST="C:\Users\PersonA\Documents\Test\Destination\%STAMP%"
robocopy %SOURCE% %DEST% /e
forfiles -p "C:\Users\PersonA\Documents\Test\Destination\" -s -m *.* -d -3 -c "cmd /c echo @file"
我已经为 FolderName 和 Current Date and Time 添加了时间戳并连接起来。
但是,我正在为他删除超过 3 天的任何内容而苦苦挣扎,目前该过程只是在复制,但我需要的是一个过程来检测修改日期或创建日期并使用我生成的代码删除超过 3 天的目录. 我在上面添加的已删除命令似乎根本没有做任何事情。
如果有人可以提供帮助,我将不胜感激。
先感谢您
解决方案
我会推荐这样的东西:
SET STAMP=%DATE:/=-% %TIME::=.%
SET SOURCE="C:\Users\PersonA\Documents\Test\Source"
SET DEST="C:\Users\PersonA\Documents\Test\Destination\%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 \Users\PersonA\Documents\Test\Destination\
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"
这是从这篇文章中给出的答案推断出来的。
推荐阅读
- php - 网站在主机上加载正常,但在外部连接上加载不正常
- javascript - 无法在 highcharts 饼图中使用 ShowInLegend 属性和 drawTable
- python - 如果重叠,一键激活多个按钮
- javascript - touchmove 不应该自动触发 mousemove 吗?
- github - 如何阻止 VSCode CI 服务器重试 1400 次
- amazon-web-services - 删除 CloudFront 后删除 ACM 证书
- python - 在 Python 中创建内置数组对象的 C-API 接口是什么?
- arrays - AVQueuePlayer 不会停止播放
- django - 如何从 django 管理站点中删除更改密码链接?
- apache-kafka - Flink流表使用kafka源码和使用flink sql查询