|
sziang
新手上路

积分 16
发帖 7
注册 2008-8-18
状态 离线
|
『楼 主』:
[已结]批处理自动删除N天之前文件目录
使用 LLM 解释/回答一下
我是单位的临时网管,备份OA服务器的数据是每天的工作内容之一,现在我是把OA服务器上应当备份的文件夹和文件进行全盘复制到以当天日期命名(如2008-08-18)生成的一个文件夹中(也是批处理,每天自动执行),由于备份的内容赿来赿大(备份一次达27.6G),我想求一个在备份的之前能够自动删除五天之前的备份目录(只保留五天的备份记录即可)的批处理文件,先谢了!我的系统是XP_SP1
Last edited by HAT on 2008-10-20 at 23:35 ]
I am a temporary network administrator in my unit. Backing up the data of the OA server is one of the daily work contents. Now I am copying all the folders and files that should be backed up on the OA server to a folder named with the current date (such as 2008-08-18) in full, and it is also a batch processing that is automatically executed every day. Since the content of the backup is getting larger and larger (a backup reaches 27.6G), I want to find a batch processing file that can automatically delete the backup directories older than five days before the backup (only keep the backup records of the past five days). Thanks in advance! My system is XP_SP1
Last edited by HAT on 2008-10-20 at 23:35 ]
|
|
2008-8-18 16:03 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
@echo off
>"%temp%\MyDate.vbs" echo dt=date()-5
>>"%temp%\MyDate.vbs" echo s=right(year(dt),4) ^& "-" ^& right("0" ^& month(dt),2) ^& "-" ^& right("0" ^& day(dt),2)
>>"%temp%\MyDate.vbs" echo wscript.echo s
for /f %%a in ('cscript /nologo "%temp%\MyDate.vbs"') do set FiveDay=%%a
for /f %%a in ('dir /b /ad') do (
if "%%a" lss "%FiveDay%" (
echo rd /s /q "%%a"
)
)
```@echo off
>"%temp%\MyDate.vbs" echo dt=date()-5
>>"%temp%\MyDate.vbs" echo s=right(year(dt),4) ^& "-" ^& right("0" ^& month(dt),2) ^& "-" ^& right("0" ^& day(dt),2)
>>"%temp%\MyDate.vbs" echo wscript.echo s
for /f %%a in ('cscript /nologo "%temp%\MyDate.vbs"') do set FiveDay=%%a
for /f %%a in ('dir /b /ad') do (
if "%%a" lss "%FiveDay%" (
echo rd /s /q "%%a"
)
)
```
|

 |
|
2008-8-18 16:26 |
|
|
sziang
新手上路

积分 16
发帖 7
注册 2008-8-18
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
非常感谢HAT朋友的答复!刚刚我将上述批处理放到目录中测试无效。我是在D盘根目录建一个000文件夹,将服务器文件(含目录)备份到此目录中分别生成的2008-08-12至2008-08-18的文件夹之中,现在只想保留2008-08-14之后的,请问怎么操作?不好意思,我是dos盲,请说具体点,再次谢谢!
Thank you very much for the reply from friend HAT! Just now I tested the above batch file in the directory and it didn't work. I created a 000 folder in the root directory of drive D, and backed up the server files (including directories) to the folders from 2008-08-12 to 2008-08-18 generated in this directory. Now I just want to keep those after 2008-08-14. How to operate? I'm sorry, I'm a DOS newbie. Please be specific. Thanks again!
|
|
2008-8-18 17:41 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
@echo off
>"%temp%\MyDate.vbs" echo dt=date()-5
>>"%temp%\MyDate.vbs" echo s=right(year(dt),4) ^& "-" ^& right("0" ^& month(dt),2) ^& "-" ^& right("0" ^& day(dt),2)
>>"%temp%\MyDate.vbs" echo wscript.echo s
for /f %%a in ('cscript /nologo "%temp%\MyDate.vbs"') do set FiveDay=%%a
for /f %%a in ('dir /b /ad "D:\000"') do (
if "%%a" lss "%FiveDay%" (
rd /s /q "%%a"
)
)
```batch
@echo off
>"%temp%\MyDate.vbs" echo dt=date()-5
>>"%temp%\MyDate.vbs" echo s=right(year(dt),4) ^& "-" ^& right("0" ^& month(dt),2) ^& "-" ^& right("0" ^& day(dt),2)
>>"%temp%\MyDate.vbs" echo wscript.echo s
for /f %%a in ('cscript /nologo "%temp%\MyDate.vbs"') do set FiveDay=%%a
for /f %%a in ('dir /b /ad "D:\000"') do (
if "%%a" lss "%FiveDay%" (
rd /s /q "%%a"
)
)
```
|

 |
|
2008-8-18 17:48 |
|
|
sziang
新手上路

积分 16
发帖 7
注册 2008-8-18
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
测试还是不成功。。。。说具体点,谢了
The test is still not successful... Please be more specific, thanks.
|
|
2008-8-18 18:22 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
把代码保存为xxx.bat
双击运行
把结果贴出来看看
>"%temp%\MyDate.vbs" echo dt=date()-5
>>"%temp%\MyDate.vbs" echo s=right(year(dt),4) ^& "-" ^& right("0" ^& month(dt),2) ^& "-" ^& right("0" ^& day(dt),2)
>>"%temp%\MyDate.vbs" echo wscript.echo s
for /f %%a in ('cscript /nologo "%temp%\MyDate.vbs"') do set FiveDay=%%a
for /f %%a in ('dir /b /ad "D:\000"') do (
if "%%a" lss "%FiveDay%" (
rd /s /q "D:\000\%%a"
)
)
pause
Save the code as xxx.bat. Double-click to run it and paste the result here.
>"%temp%\MyDate.vbs" echo dt=date()-5
>>"%temp%\MyDate.vbs" echo s=right(year(dt),4) ^& "-" ^& right("0" ^& month(dt),2) ^& "-" ^& right("0" ^& day(dt),2)
>>"%temp%\MyDate.vbs" echo wscript.echo s
for /f %%a in ('cscript /nologo "%temp%\MyDate.vbs"') do set FiveDay=%%a
for /f %%a in ('dir /b /ad "D:\000"') do (
if "%%a" lss "%FiveDay%" (
rd /s /q "D:\000\%%a"
)
)
pause
|

 |
|
2008-8-18 19:24 |
|
|
abcd
银牌会员
    
积分 1436
发帖 739
注册 2007-10-11
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
这种东西,论坛早有,就不要回帖和发帖了。
Such things already exist in the forum, so don't post or reply.
|
|
2008-8-18 20:35 |
|
|
sziang
新手上路

积分 16
发帖 7
注册 2008-8-18
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
运行结果,图片已上传
Last edited by sziang on 2008-8-19 at 10:34 AM ]
Running result, the picture has been uploaded
Last edited by sziang on 2008-8-19 at 10:34 AM ]
|
|
2008-8-19 10:10 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
看不到图片。
先把图片上传到论坛,再把链接放到img标签里面即可。
Can't see the picture. First, upload the picture to the forum, then put the link inside the img tag.
|

 |
|
2008-8-19 10:47 |
|
|
wangwei4106
新手上路

积分 15
发帖 8
注册 2008-8-19
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
来混点积分看高级点的······
Come to earn some points to view higher-level ones...
|
|
2008-8-19 10:53 |
|
|
sziang
新手上路

积分 16
发帖 7
注册 2008-8-18
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
D盘根目录下备份文件夹000

bat文件

bat文件运行情况
Last edited by sziang on 2008-8-19 at 03:34 PM ]
Backup folder 000 in the root directory of drive D

bat file

Running situation of bat file
Last edited by sziang on 2008-8-19 at 03:34 PM ]
|
|
2008-8-19 15:29 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
运行6楼的代码,结果贴出来看看
Run the code on the 6th floor and post the result for us to see.
|

 |
|
2008-8-19 15:32 |
|
|
sziang
新手上路

积分 16
发帖 7
注册 2008-8-18
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
看到图片了吗,请帮忙
Did you see the picture? Please help
|
|
2008-8-19 16:35 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
代码更正如下:
>"%temp%\MyDate.vbs" echo dt=date()-5
>>"%temp%\MyDate.vbs" echo s=right(year(dt),4) ^& "-" ^& right("0" ^& month(dt),2) ^& "-" ^& right("0" ^& day(dt),2)
>>"%temp%\MyDate.vbs" echo wscript.echo s
for /f %%a in ('cscript /nologo "%temp%\MyDate.vbs"') do set FiveDay=%%a
for /f "tokens=*" %%a in ('dir /b /ad "D:\000"') do (
if "%%a" lss "%FiveDay%" (
rd /s /q "D:\000\%%a"
)
)
pause
The code correction is as follows:
>"%temp%\MyDate.vbs" echo dt=date()-5
>>"%temp%\MyDate.vbs" echo s=right(year(dt),4) ^& "-" ^& right("0" ^& month(dt),2) ^& "-" ^& right("0" ^& day(dt),2)
>>"%temp%\MyDate.vbs" echo wscript.echo s
for /f %%a in ('cscript /nologo "%temp%\MyDate.vbs"') do set FiveDay=%%a
for /f "tokens=*" %%a in ('dir /b /ad "D:\000"') do (
if "%%a" lss "%FiveDay%" (
rd /s /q "D:\000\%%a"
)
)
pause
|

 |
|
2008-8-19 17:21 |
|
|
sziang
新手上路

积分 16
发帖 7
注册 2008-8-18
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
还是没有用,运行结果和我那天发的一样
Still no use, the running result is the same as I posted that day
|
|
2008-8-21 15:47 |
|