如何通过与同一日期的所有文件创建一个档案归档超过7天,7-ZIP旧文件 [英] How to archive files older than 7 days with 7-ZIP by creating one archive for all files with same date

查看:443
本文介绍了如何通过与同一日期的所有文件创建一个档案归档超过7天,7-ZIP旧文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很密切的解决我的问题,一切都在这个问题描述:
<一href=\"http://stackoverflow.com/questions/25079261/how-to-archive-files-older-than-7-days-with-creating-one-archive-for-all-files-w/25083336?noredirect=1#comment39325687_25083336\">How与同日,所有文件创建一个档案归档超过7天以上的文件?

问题是,我需要的7-Zip类似这样的另一种解决方案,但工作,这有可能成为该bat文件,我相信codeD由于在7-Zip的不-to7d开关好像有在WinRAR的。

在code现在(幸得@Mofi创建此):

 关闭@echoSETLOCAL ENABLEEXTENSIONS EnableDelayedExpansion
REM定义的目录用于备份任务。
设置LogDirectory = D:\\ TET \\ Web3811 \\ Web3811 \\日志
设置BakDirectory = D:\\ TET \\ Web3811 \\ Web3811 \\ LogsBackupREM获取日志目录中的所有文件名成最后排序的列表文件
REM修改日期与顶部最旧的文件,并在最新的底部。
REM注:/ S得到完整路径的文件名是很重要的。
目录%LogDirectory%\\ */ A-D / B / OD / S / TW 1&gt;中%BakDirectory%\\ LogFiles.lst2 - ; NUL
REM跳转到清理阶段,如果没有文件中的日志目录中找到。
如果ERRORLEVEL 1页转到:清理REM删除列表文件与同一天的所有文件,如果文件存在
REM例如,从该批处理文件的previous执行
REM这是在执行过程中手动终止由用户。
如果存在%BakDirectory%\\ DayFiles.lst删除%BakDirectory%\\ DayFiles.lst设置LastDate =无
FOR / F有usebackq delims =%% f由于(%BakDirectory%\\ LogFiles.lst)做(   设置FILETIME = %%〜TF   REM得到的只是从文件的时间格式DD-MM-YYYY文件的日期。
   REM文件时间字符串格式取决于日期和时间
   REM格式定义在Windows语言设置。
   REM因此,线下必须适应,如果日期格式
   REM是是否DD.MM.YYYY也不是DD-MM-YYYY也不DD / MM / YYYY。
   设置FILEDATE = FILETIME:〜6,4 - FILETIME:!!!〜3,2 - FILETIME:!〜0,2!   REM这是不同的文件的最后修改日期
   REM到previous文件的最后修改日期?
   如果不是!FILEDATE!==!LastDate! (
      REM没有在第一个区别归档。
      如果不是LastDate!==无的号召:归档日志
      REM退出循环,如果RAR未归档,这意味着任何文件
      REM所有其他文件在过去7天内修改。
      如果!LastDate!==ExitLoop转到清理
      REM开始创建一个新的列表。
      设置LastDate =!FILEDATE!
   )
   该文件与路径,以当日列表REM追加名字。
   回声%% F&GT;&gt;中%BakDirectory%\\ DayFiles.lst
)REM跳转到清理阶段,如果与文件中没有列表文件存档。
如果不存在%BakDirectory%\\ DayFiles.lst转到清理与创建或修改内没有日志文件,否则REM
REM过去7天,但至少有一个较旧的文件存在
REM尽管如此,在存档列表文件所有这些文件。
拨打:归档日志:清理
德尔%BakDirectory%\\ LogFiles.lst
ENDLOCAL
GOTO:EOF:归档日志
C:\\ Program Files文件(x86)的\\ 7-Zip的\\ 7z压缩-sdel一个-MMT -mx3 -tzip!%BakDirectory%\\ LastDate _Logs.zip@%BakDirectory%\\ DayFiles.lst如果错误级别10集LastDate = ExitLoop
德尔%BakDirectory%\\ DayFiles.lst

基本上有只需要添加一个检查检查是否修改日期=超过7天以上。
我不知道如何实现这一点,因为一旦你运行:归档日志的7-Zip将只取该文件夹中的一切,只要我可以看到有没有开关以检查

我认为我们必须做这样的事情:


    检查
  • code如果文件的修改日期7天以上和放大器;保存的文件名中的值


  

:ZipOnlyafter7days结果
      适用于:结果
      C:\\ Program Files文件(x86)的\\ 7-Zip的\\ 7z压缩-sdel一个-MMT -mx3 -tzip%BakDirectory%LastDate _Logs.zip!@%BakDirectory%\\ Filename_Value



解决方案

您应该使用带/超过maxage的Robocopy:7选项相关文件复制到一个临时文件夹,然后COM preSS全部使用7zip的文件。

There is a CLOSE solution to my problem, and everything is described in this question: How to archive files older than 7 days with creating one archive for all files with same date?

The thing is, i need another solution similar to this but working for 7-Zip, this has to be coded in the bat file i believe since there is no -to7d switch in 7-Zip like there is in Winrar.

The Code right now ( Credit goes to @Mofi for creating this ):

@echo off

setlocal EnableExtensions EnableDelayedExpansion
rem Define the directories to use for backup task.
set "LogDirectory=D:\tet\Web3811\Web3811\log"
set "BakDirectory=D:\tet\Web3811\Web3811\LogsBackup"

rem Get all file names in log directory into a list file sorted by last
rem modification date with oldest file at top and newest at bottom.
rem Note: /S is important to get the file names with complete path.
dir "%LogDirectory%\*" /A-D /B /OD /S /TW 1>"%BakDirectory%\LogFiles.lst" 2>nul
rem Jump to clean up stage if no file found in the log directory.
if errorlevel 1 goto :CleanUp

rem Delete list file for all files with same day if file exists
rem for example from a previous execution of this batch file
rem which was terminated manually by a user during execution.
if exist "%BakDirectory%\DayFiles.lst" del "%BakDirectory%\DayFiles.lst"

set LastDate=none
for /F "usebackq delims=" %%F in ( "%BakDirectory%\LogFiles.lst" ) do (

   set FileTime=%%~tF

   rem Get just file date from file time in format DD-MM-YYYY.
   rem The file time string format depends on date and time
   rem format definition in Windows language settings.
   rem Therefore the line below must be adapted if date format
   rem is whether DD.MM.YYYY nor DD-MM-YYYY nor DD/MM/YYYY.
   set FileDate=!FileTime:~6,4!-!FileTime:~3,2!-!FileTime:~0,2!

   rem Is the last modification date of this file different
   rem to last modification date of the previous file?
   if not "!FileDate!"=="!LastDate!" (
      rem Nothing to archive on first difference.
      if not "!LastDate!"=="none" call :ArchiveLogs
      rem Exit loop if RAR has not archived any file which means
      rem all other files are modified within the last 7 days.
      if "!LastDate!"=="ExitLoop" goto CleanUp
      rem Start creating a new list.
      set LastDate=!FileDate!
   )
   rem Append name of this file with path to current day list.
   echo %%F>>"%BakDirectory%\DayFiles.lst"
)

rem Jump to clean up stage if no list file with files to archive.
if not exist "%BakDirectory%\DayFiles.lst" goto CleanUp

rem Otherwise with no log file created or modified within
rem the last 7 days, but at least one older file exists
rem nevertheless, archive all those files in list file.
call :ArchiveLogs

:CleanUp
del "%BakDirectory%\LogFiles.lst"
endlocal
goto :EOF

:ArchiveLogs
"C:\Program Files (x86)\7-Zip\7z" -sdel a -mmt -mx3 -tzip "%BakDirectory%\!LastDate!_Logs.zip" "@%BakDirectory%\DayFiles.lst"

if errorlevel 10 set LastDate=ExitLoop
del "%BakDirectory%\DayFiles.lst"

Basically there just needs to be added a check that check if Modified date = older than 7 days. i'm not sure how to implement this, since once you run the :ArchiveLogs 7-Zip will just take EVERYTHING in that folder and as far as i can see there are no switches to check for that.

I believe we have to do something like this:

  • Code to check if file has a modification date older than 7 days & save that file name in a value.

:ZipOnlyafter7days
For:
"C:\Program Files (x86)\7-Zip\7z" -sdel a -mmt -mx3 -tzip "%BakDirectory%!LastDate!_Logs.zip" "@%BakDirectory%\ Filename_Value "

解决方案

You should use robocopy with the /maxage:7 option to copy relevant files to a temp folder, and then compress all the files using 7zip.

这篇关于如何通过与同一日期的所有文件创建一个档案归档超过7天,7-ZIP旧文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆