當有大量檔案搬移時,大部分的人應該都直接複製貼上(應該不會用剪下班吧?)的功能。
但是對於大量的檔案真的搬過去就沒問題了嗎? 如果是幾千張照片,一旦複製出錯,或是另一顆硬碟有壞軌,這樣下次開圖時,就會有破圖的狀況出現了。
這種情況是可以避免的。
所以在網路找了一下,有一個方便的微軟工具 FCIV (File Checksum Integrity Verifier) 可以輕鬆幫我們比對。
簡單的比對當然是沒問題,但是自動化比對,就需要點技巧了。
下面的範例是我測試一個RAID用的流程,若比對有問題會自行產生一個LOG檔並記錄下來,並不能直接拿來使用喔。
首先我們先簡單畫一個流程圖以方便邏輯思考.... (有阿茲海默症跡象了,這樣可以避免我的腦袋打結)
確定需要的功能後,利用Windows 的 CMD模式建立批次檔;
這一次共要建立2個檔案:
1. begin.cmd
2. create CRC XML.cmd
因為FCIV需要先產生來源資料夾的檔案,所以先寫一個批次檔自動產生
首先是 begin.cmd:
@echo off
color 0e
title Files Integrity Verifier Powered : 菜不切
set file=LOG.dat
echo >> %file%
:Start
rem echo Please press any ley to continue
rem Pause>nul
cls
echo ****************************************************************************
echo.
echo.
echo. Integrity Verifier V1.0 菜不切
echo.
echo.
echo. Step1: Write test files to RAID group
echo. Step2: Compare MD5 between HOST and RAID group
echo. Step3: Erase test data from RAID location
echo.
echo.
echo ****************************************************************************
echo.
echo.
echo.
echo.
echo.
echo. Please press any key to continue
pause>nul
:in_er
cls
echo ****************************************************************************
echo.
echo. Please intput RAID group location then press any key to continue
echo.
echo ****************************************************************************
echo.
echo.
echo.
echo.
rem SET select=
SET /P select= Input your RAID location [A~Z]:
rem IF NOT '%select%'=='' SET Choice=%select:~0,1%
rem IF '%select%'='nul' then GOTO in_er
echo.
echo.
echo.
echo.
echo. Make sure your RAID group location is [ %select%: ]
echo.
echo.
echo. ----------------------------------------------------
echo. Correct: Please press any key to continue
echo. Wrong: Please press [ctrl+C] to leave CMD mode
echo. ----------------------------------------------------
echo.
pause>nul
echo %DATE% >> LOG.dat
rem ,,,,,
rem if not exist %select%: goto disk_err
rem GOTO in_er
rem **********************************************************
rem Step 1
rem **********************************************************
:s1
cls
echo.
echo. Step1................................Write fiels to RAID group
echo. -----------------------------
echo. copy file to Disk
echo. -----------------------------
echo "-----START-----" >> LOG.dat
echo %time% >> LOG.dat
copy files\*.* %select%:\files
if errorlevel 1 goto s1w_err
cls
echo. Step2................................verify CRC
echo. ------------------------------
echo. Verify CRC
echo. ------------------------------
fciv %select%:\files -v -xml www.xml >> report.txt
if errorlevel 1 goto record
:step3
cls
echo. Step3................................erase test data from RAID
echo. ------------------------------
echo. erase test data from RAID
echo. ------------------------------
del %select%:\files\*.* /q
if errorlevel 1 goto s1e_err
echo.
echo. Erease completed
echo.
echo.
echo.
echo %time% >> LOG.dat
echo "-----END-------" >> LOG.dat
echo " " >> LOG.dat
echo.
echo.
echo.
echo.
echo.
goto s1
:s1w_err
cls
type write.dat
pause>nul
goto s1
:s1e_err
cls
type second.dat
pause>nul
goto s1
:disk_err
cls
type disk_err.dat
pause>nul
goto s1
:record
echo --------- >>err.txt
echo. an error occur , Date= %date% , Time= %time% >> err.txt
echo --------- >> err.txt
goto step3
rem **********************************************************
rem END
rem **********************************************************
:end
第二部分是 create CRC XML.cmd
@echo off
color 0e
title Files Integrity Verifier,. Powered : 菜不切
set file=LOG.dat
echo >> %file%
:Start
cls
echo ****************************************************************************
echo.
echo.
echo. Integrity Verifier V1.0 菜不切
echo.
echo ****************************************************************************
echo.
echo.
echo.
SET /P select= Input your RAID group location[A~Z]:
echo.
echo.
echo.
echo.
echo. Make sure your RAID group location is [ %select%: ]
echo.
echo.
echo. ------------------------------------------------
echo. Correct,Please press any key to continue
echo. Wrong,Please close the cmd and re-execute.
echo. ------------------------------------------------
pause>nul
copy files\*.dat %select%:\files
fciv %select%:\files -r -xml www.xml
del %select%:\files /Q
檔案比對完一次,會自動記錄於LOG檔,下面的照片是OK跟NG時的比對
程式最後,因為是測試迴圈與裝置檔案用,所以當然loop[最後就delete掉了,有需要的朋友,可以自行修改自己所需。
以下是使用的方式,其實滿簡單的:
1. create and save some files to files folder, then rename all file name to *.dat
2. execute "create CRC XML" , the program will create a www.xml file.
3. execute begin.bat, follow program indicator to complete test setting.
留言列表