Board logo

标题: [求助]备份最进30天,超过了删除最早的。求高手帮忙 [打印本页]

作者: zhiyangchen     时间: 2007-9-16 10:43    标题: [求助]备份最进30天,超过了删除最早的。求高手帮忙

搞一个批处理 有一个目录,需要每天晚上9点,备份到最后一个分区的”temp“文件夹里。 检测"temp"文件夹,如果里面的文件夹数超过了30个,那么删除最早的那一个。 各位大哥大姐帮帮我啊。。小弟在此谢过了 用过搜索了 找不到我要的啊,而且很多都看不懂 :mad:

作者: zhiyangchen     时间: 2007-9-16 11:09
高手都不屑于帮我这种小问题 哎。。。。。。。。。。。。

作者: zhiyangchen     时间: 2007-9-27 08:57
有没有人能帮帮我啊?

作者: ZJHJ     时间: 2007-9-28 23:46
你可以将备份的文件命名为1.xxx,每备份一次改变增大+1,如果检测到31.xxx,即del

作者: acme     时间: 2007-10-8 20:54
我也想知道,高手呢?

作者: l80d     时间: 2007-10-8 21:29
MoveOldFiles.cmd @echo off if "%1"=="" goto _usage set dst=.\. if not "%2"=="" if exist %2\. (set dst=%2\.) else (goto _err1) for /r %dst% %%f in (*.*) do if %%~tf LSS %1 Move /y %%f D:\backup\ && echo Move %%f goto _quit :_usage echo DelOldFile.cmd Move files before assigned folder and date echo Version 1.0 Copyleft by Climbing echo syntax: DelOldFile ^<Date^> [target Folder] echo ^<Date^> Must assigned parameter,Date format:%date%,Files before the assigned date will be moveed(not include the assigned date) echo [target Folder] Optional parameter,Assign the folder which files want to be moveed,default is current folder goto _quit :_err1 echo Err:Assigned folder:%2 not exist! :_quit set dst= :End 用法: MoveOldFiles 2007-08-15 D:\Logs 把2007-08-15以前在D:\Logs下的文件,移动到D:\backup\下 [ Last edited by l80d on 2007-10-8 at 09:34 PM ]

作者: james168     时间: 2007-10-9 12:20
试试这个: SRC为源目录 X: 为temp所在的磁盘 有个要求:目录名不能包含空格
@echo off
title delete old folder when great 30 by james168
xcopy /s /q SRC X:\temp
for /f "skip=5 tokens=1,2 delims= " %%a in ('dir /ad /ogd X:\temp') do (
  if "%%b"=="个目录" set TOTAL=%%a
)
if %TOTAL% leq 32 goto notdel
set /a GRT=%TOTAL%-32
set NUM=0
for /f "tokens=1 delims= " %%j in ('dir /ad /ogd /b') do (call :dd1 "%%j")
goto end

:notdel
echo.
echo   Folder less than 30
goto end

:end
echo Press any key exit
pause>nul
exit

:dd1
set /a NUM+=1
if %NUM% leq %GRT% (rd /q /s X:\temp\%1)
goto :eof
[ Last edited by james168 on 2007-10-9 at 12:30 PM ]

作者: honghunter     时间: 2007-12-18 10:20
研究7楼代码,希望能变成支持目录空格的。

作者: everest79     时间: 2007-12-18 11:08
在论坛里搜索 一百天|100天

作者: honghunter     时间: 2007-12-18 12:48
@echo off goto :startit @REM/ 原作者:james168 @REM/ 摘自:www.cn-dos.net/forum ... 7楼 @REM/ @REM/ 修改者:honghunter www.dps4e.com @REM/ 作用:将%src_dir%中的内容复制/备份到%tar_dir%. @REM/ 最多保留30个备份,超过30的时候,删除最早的备份。 @REM/ 备份目录名称为备份时的日期 @REM/ 注意:如果某天备份不止一次,从第二次开始,目录名称上面将增加序号。 @REM/ @REM/ honghunter 在 winXP+SP2的CMD下测试通过。 @REM/ :startit set CCDIR=%~dp0 set CCDIR=%CCDIR:~0,-1% set src_dir=%USERPROFILE%\Favorites set tar_dir=B:\JatDomeR5 title delete old folder when great 30 set target_dir=%tar_dir%\%DATE%\ set /a fix_dir=0 @REM/ 如果当天备份过,目录名称上面增加序号。 :get_target_dir set /a fix_dir=%fix_dir%+1 if exist "%target_dir%\." set target_dir=%tar_dir%\%DATE%_%fix_dir%\ if exist "%target_dir%\." goto :get_target_dir echo --------- Backup --------- echo From : %src_dir% echo To : %target_dir% echo -------------------------- xcopy /s /q "%src_dir%\*.*" %target_dir% @REM/goto :eof for /f "skip=5 tokens=1,2 delims= " %%a in ('dir /ad /ogd %tar_dir%') do ( if "%%b"=="个目录" set TOTAL=%%a ) if %TOTAL% leq 32 goto notdel set /a GRT=%TOTAL%-32 set NUM=0 for /f "tokens=1 delims= " %%j in ('dir /ad /ogd /b %tar_dir%') do (call :dd1 "%%j") GOTO end :notdel echo. echo Folder less than 30 goto end :end echo Press any key exit @REM/pause>nul @REM/exit :dd1 set /a NUM+=1 if "%1"=="" goto :eof if "%1"==" " goto :eof if %NUM% leq %GRT% (rd /q /s %tar_dir%\%1) goto :eof

作者: kavenlee72     时间: 2007-12-26 23:19
有没有在DOS7.1下能用的?谢谢了