| 1. |
Solve : Corrupted file detection methods thru batch & replace mismatched files etc? |
|
Answer» So my one computer I thought was protected by a battery backup and the 7 year old battery backup dropped like a stone during a short outage killing the computer mid process of some write processes. Microsoft Windows XP [Version 5.1.2600] Just an update... Digging online for methods using FC, I came across Foxidrive's response here http://www.pcreview.co.uk/forums/fc-exe-return-value-t2441497.html With this back in 2006 for another person looking for a batch method use of FC for 2 files ... Code: [Select]echo off fc /b file1 file2|find /i "no differences">nul if errorlevel 1 echo miscompare if not errorlevel 1 echo compared ok Looks like if I make it like this, but able to test among any number of files in any number of folders between 2 root folder locations, it might work, although I need the checking to be between all files between the C:\Data\ and H:\Backup\ Quote echo off In red.... - I am unsure how to accomplish using the path from that of which the file was found and compared against to have this dynamic path for the fact that I cant think of a better way to explain it, get passed into a variable such as %dyn_path% in which I think I have to use SET %dyn_path% = ( the actual path to file, but not sure how to get this). Above I show %dyn_path% and %dyn_filename% .... this might be able to be passed for say C:\Data\Project1\test1.cpp directly into %dyn_path% without having to have C:\Data\Project1\ passed into %dyn_path% and test1.cpp passed directly into %dyn_filename% - Not sure also how to start at first file/folder alphanumerically to test all files in all folders between C:\Data\ and H:\Backup\ until End Of Files & Folders is found. Not sure if the best method to test between C:\Data\ and H:\Backup\ would be to create a copy of the entire directory trees between C:\Data\ and H:\Backup\ by use of an XCOPY TRICK where you can actually have it perform an XCOPY without writing files and have this info that is normally displayed written to file and then have a FOR loop that imports each line 1 by 1 which holds the paths to the files, and by use of a counter, can know to read in the path from say line 44 of this XCOPY text file that holds a copy of the directory tree to test against. This XCOPY tree would be generated from that of the C:\Data\ and to trick xcopy into thinking that it would normally need to copy files to say the root of H:\ to avoid error condition of cyclic copy condition, but instead of copying the files and folders list all paths with files would be to use of the /F ( full paths )and /L ( display only )switches and sending the output via > to TreeLayout.txt which is then read by the loop with the FC instructions and IF THEN ELSE logic of true or false for match or mismatch. Are the trees c:\data and h:\backup the same trees? Just 7 days different? (plus corrupted files) Quote Are the trees c:\data and h:\backup the same trees? Hello foxidrive Yes they are exactly the same trees and up to 7 days different since the backup is performed weekly. Right now I have held off on the backup to that external until i can get this issue resolved and instead am just saving data to a 32GB flash stick.This is untested: It will do a fairly swift compare for files that are missing and files that have different sizes and will create a batch file (which has a .txt extension for you to check first for any obvious errors) fc_compare.C.bat.txt The batch file is designed to compare the files with the same filesize and write a report if there is a binary mismatch. This will take much longer if there is a lot of GB of data involved. All log files will be written to the desktop. Code: [Select]echo off dir "c:\data" /b /s /a-d >"%userprofile%\desktop\c_data.txt" for /f "usebackq tokens=1,2,* delims=\" %%a in ("%userprofile%\desktop\c_data.txt") do ( if not exist "h:\backup\%%c" (>>"%userprofile%\desktop\h_data_missing.txt" echo missing "h:\backup\%%c") if exist "h:\backup\%%c" ( for %%m in ("c:\data\%%c") do for %%n in ("h:\backup\%%c") do ( if %%~zn EQU %%~zm ( >>"%userprofile%\desktop\fc_compare.C.bat.txt" echo fc /b "c:\data\%%c" "h:\backup\%%c" ^>nul ^|^| ^(^>^>"%userprofile%\desktop\fc_compare.result_C.txt" echo data mismatch in "c:\data\%%c" and "h:\backup\%%c"^) ) else ( >>"%userprofile%\desktop\fc_compare.C.size_mismatch.txt" echo size mismatch in "c:\data\%%c" and "h:\backup\%%c" ) ) ) dir "h:\backup" /b /s /a-d >"%userprofile%\desktop\h_data.txt" for /f "usebackq tokens=1,2,* delims=\" %%a in ("%userprofile%\desktop\h_data.txt") do ( if not exist "c:\data\%%c" (>>"%userprofile%\desktop\c_data_missing.txt" echo missing "c:\data\%%c") ) echo see if any errors appear on the console above pause hmm... so I am testing this on a Windows 7 64-bit system and it creates a c_data.txt file to desktop, but ends there. I ran this from cmd shell and it runs and exits back to C:\> so it seems to be terminating too early for some reason as for it never gets to the pause. The file on the desktop c_data.txt I have the following files in as copy/pasted from this file here. Quote c:\data\test1.txt It seems as though its carrying out this action and ending here: Code: [Select]dir "c:\data" /b /s /a-d >"%userprofile%\desktop\c_data.txt" This is where it leaves me off at after running, back to command prompt. And the directory info is written to file that is passed to desktop. Quote C:\batches>run_compare1.batI'd forgotten about that task. Did it take 2 weeks to run? It was missing a closing parenthesis IIANM so try this. Code: [Select]echo off dir "c:\data" /b /s /a-d >"%userprofile%\desktop\c_data.txt" for /f "usebackq tokens=1,2,* delims=\" %%a in ("%userprofile%\desktop\c_data.txt") do ( if not exist "h:\backup\%%c" (>>"%userprofile%\desktop\h_data_missing.txt" echo missing "h:\backup\%%c") if exist "h:\backup\%%c" ( for %%m in ("c:\data\%%c") do for %%n in ("h:\backup\%%c") do ( if %%~zn EQU %%~zm ( >>"%userprofile%\desktop\fc_compare.C.bat.txt" echo fc /b "c:\data\%%c" "h:\backup\%%c" ^>nul ^|^| ^(^>^>"%userprofile%\desktop\fc_compare.result_C.txt" echo data mismatch in "c:\data\%%c" and "h:\backup\%%c"^) ) else ( >>"%userprofile%\desktop\fc_compare.C.size_mismatch.txt" echo size mismatch in "c:\data\%%c" and "h:\backup\%%c" ) ) )) echo stage one hacked&pause dir "h:\backup" /b /s /a-d >"%userprofile%\desktop\h_data.txt" for /f "usebackq tokens=1,2,* delims=\" %%a in ("%userprofile%\desktop\h_data.txt") do ( if not exist "c:\data\%%c" (>>"%userprofile%\desktop\c_data_missing.txt" echo missing "c:\data\%%c") ) echo see if any errors appear on the console above pause Quote I'd forgotten about that task. Did it take 2 weeks to run? Actually I just finally got around to testing it ... Looking forward to getting back to normal 40 hr work weeks vs these 60s. It wont be another 2 weeks before I test this though. Thanks for your help with this. Sweet this works perfect.... Thanks for your help with this. |
|