Menu

Script for Testing and delete corrupted Files with 7ZIP

Help
Staeubling
2013-03-11
2013-03-20
  • Staeubling

    Staeubling - 2013-03-11

    Hello,
    sorry for my simple english, i have a big Problem with corrupted Zip-Files on my NAS.
    I desperately need your help.
    I am looking for a script (batch, PowerShell whatever) for Check Zip-Files and deleted coruppted Files automatically.
    I have on a NAS over 300 folders with 600 Zip Archives from backups from various Notebooks.
    These ZIP files are often broken because when creating either broke off the connection or the user has aborted manually the backup.
    The script is what I seek, so test all zip files at once in different directories and delete all e corrupted archives.

    My idea was a call like in Exampel:
    7z t \NAS\backup *. Zip-r
    Unfortunately, the call of all files in all subdirectories does not delete corrupter and the files either.
    Can you help me create a script for testing Archives and delete Files while the scan?

    Greetings
    Micha

     
  • fernando

    fernando - 2013-03-11

    logic:
    starting at the directory \\NAS\backup
    recursively search for .ZIP files
    test each one with 7-Zip
    if the string "Everything is Ok" is NOT found,
    delete the .ZIP

    try batch script like:

        FOR /R \\NAS\backup %%A IN (*.zip) DO (
        7z t "%%A" | FIND "Everything is Ok" || DEL "%%A"
        )
    

    see code.txt attached to this forum posting for unaltered code

     
    • Staeubling

      Staeubling - 2013-03-12

      Hi Fernando,

      thats working fine and is a very quick scan with delete corrupted Files.
      Many Thanks.
      I now wanted to let even create a log file when a file is deleted.
      That does not work or if a log is written, then the correct file and not the corrupted Files log.
      Doing Definitely a mistake, this time with the idea that I had not and it works:
      7z t "%%A" | FIND "Everything is Ok" || DEL "%%A" & echo %%A% >>error.log
      where is the error?
      Many thanks for Answer and sorry for my simpel english again.
      Micha

       
  • fernando

    fernando - 2013-03-12

    enclose the delete and log function in parenthesis

        FOR /R \\NAS\backup %%A IN (*.zip) DO (
        7z t "%%A" | FIND "Everything is Ok" || (DEL "%%A" & ECHO.%%A BAD >> error.log)
        )
    

    see code.txt attached to this forum posting for unaltered code

     

    Last edit: fernando 2013-03-12
  • Staeubling

    Staeubling - 2013-03-13

    Hi Fernando,
    thats working fine and is a great Work.
    The Errorlog is coorect and listed all deleted File.
    By another skript working the Error.log not correct.
    The script deleted Files when more as 3 Files in the Folder.
    The logfile listet only the first deleted File, no another deleted Files.
    Can you see my error in the Script?
    Many thanks for work.
    Script:
    net use y: \de-ber-nas002\userbackup
    cls
    for /d %%D in ("y:*") do (
    cd /d "%%D"
    for /f "skip=3 delims=" %%F in ('dir /b /o-d /a-d 2013.zip') do @echo del "%%F" & ECHO.%%F TO MANY >> error.log
    )
    net use y: /DELETE /YES

    greatings Micha

     
    • fernando

      fernando - 2013-03-14

      This forum is for 7-Zip,
      Script of 7-Zip is OK - other script is off-topic.
      I do not see why all F variable not written to log files.
      Note: in your script one log file in each directory where files deleted.
      I write 2 example scripts with slightly different function.
      Both write standard "too many" and other error reasons
      e.g. 'access denied', or 'file in use by other process'.

      See examples.txt attached to this forum posting.

       

      Last edit: fernando 2013-03-14
  • Staeubling

    Staeubling - 2013-03-14

    Hi,
    here my exact Problem:
    Script delete all Files in each Folder when more as 3 Files.
    That work korrect, in the Logfile is only one entry for one File and not for all delete Files.
    can anyone see the error?
    Script:
    for /f "skip=3 delims=" %%F in ('dir /b /o-d /a-d 2013.zip') do @echo del "%%F" &

    Thanks for Answer
    Micha

     
  • Staeubling

    Staeubling - 2013-03-15

    Hi Fernando,
    Thank you for your help and Sorry for the Off-Topic question.
    My Script is now working Fine.
    I have a Last question:-) in my Nest Post (to thema 7 Zip)

     
  • Staeubling

    Staeubling - 2013-03-15

    7Zip is Testing Fine all Zip-Files.
    Can 7zip create Or Reading Archiv-Bit?
    My Idea is, that 7Zip no Scan the Old Files by Scan again, only the New Added Files.
    Have 7Zip that Features, i have no Found in the Documentation.
    Thank you for your Geräte help.
    Micha

     
    • fernando

      fernando - 2013-03-16

      No, 7-Zip 9.20 (stable version) is not aware of Archive bit file attribute.
      Maybe a alpha or beta version has some function, I do not know.
      You will need to find the files with the A bit e.g. using DIR or ATTRIB,
      then when done processing flip the bit off with ATTRIB.

      Here is the code from article #8476
      modified to test only Zip files with the A bit, process, then flip off the A bit.

        FOR /R \\NAS\backup %%D IN (.) DO (
        PUSHD "%%D"
        FOR /F %%F IN ('DIR/A:A/B *.zip') DO (
        7z t "%%F" | FIND "Everything is Ok" || (DEL "%%F" & ECHO.%%A BAD >> error.log)
        IF EXIST "%%F" ATTRIB -A "%%F"
        )
        POPD
        )
      

      see code.txt attached to this forum posting for unaltered code

       
  • Staeubling

    Staeubling - 2013-03-17

    Hi Fernando,
    thanks for your Idea with the Attrib -a Variante.
    I tested this tomorow.
    Great Work from you.
    I give feedback to you.
    Micha

     
  • Staeubling

    Staeubling - 2013-03-18

    hi,
    the Script with attrib works not completed in all Folders.
    the first 20 Folders search the %%F Parameter the wrong Filename.
    The Filename over %%F is by scan the Foldername, after various Folder scan no the correct Filename.
    In Error.log is the rest from Parameter stored.
    Is this a limit by scan?
    I hope you understand me.
    I attached a screenshot, you can see the scan, first wrong and last the correct scan. you can see the Errorlog with rest of Parameters and the Script for this Scan (with Path Parameter for Phat for 7ZIP).
    Where is the error?

    regards Micha

     
  • fernando

    fernando - 2013-03-18

    First problem:
    Default FOR delimiter set is space and tab.
    No delimiter is wanted, else filename with space is
    tokenized and only first token is sent to 7z command.
    (Looks like directory name, but is filename before space).

    Second problem:
    Old A variable should be F variable.

    Added IF EXIST *.zip statement;
    only look for A bit zip files, if they exist.

    Try:

      FOR /R \\de-ber-NAS002\userbackup %%D IN (.) DO (
      PUSHD "%%D"
      IF EXIST *.zip (
      FOR /F "delims=" %%F IN ('DIR/A:A/B *.zip') DO (
      7z t "%%F" | FIND "Everything is Ok" || (DEL "%%F" & ECHO.%%F BAD >> error.log)
      IF EXIST "%%F" ATTRIB -A "%%F"
      )
      )
      POPD
      )
    

    see code.txt attached to this forum posting

     
  • Staeubling

    Staeubling - 2013-03-19

    Hello Fernando,
    that is great and the script is working fine.
    You have hard work and a lot of patience demonstrated.
    I hope i have a last question for you and is not Off-Toppic.
    See the Attachment for script.
    This is the Original your script, was function fine.
    I have in this script change the Original-Servername to the variable of Server (for Various Server).
    The run of 7zip don´t works over the variable SET _source unfortunately. he can not find the path.
    Replace the variable with the Servername, 7ZIP is starting.
    I'm definitely a thinking error.
    See you my error?

    best regards and thank for helps
    Micha

     
  • fernando

    fernando - 2013-03-19

    Compare your SET and FOR statements.
    You do:
    SET Var=Dir\SubDir
    Then:
    FOR... %Var%\SubDir
    So you go into Dir\SubDir\SubDir

    Use:

      FOR /R %_source%\ %%D IN (.) DO (
    
     

    Last edit: fernando 2013-03-19
  • Staeubling

    Staeubling - 2013-03-20

    Hi,
    i found my error in my script,
    7zip could not be started because the user folder backup occurred twice when calling.
    now it runs with the variable and the different call.
    What has struck me, the Mapping by start the FOR...command is permanently and by every start an new mapping the same Folder. not disconnected the Mapping after command.
    Thank you for time and patience.
    Greetings
    micha

     

Log in to post a comment.

MongoDB Logo MongoDB