I run it daily after the prune script.
It’s a very simple / ugly / hardcoded windows batch (CMD) script. I’m gradually modifying my scripts to something more parameterized and better coded, but time has been a problem ;-). Since my backups are working, I confess I’m not prioritizing this.
It basically has these steps:
(remember that everything between % and ! are variables or constants)
- Read the files from local repository, storing name and size in array:
for /f "tokens=1* delims=\" %%a in ('forfiles /s /m *.* /p %repository% /c "cmd /c echo @relpath"') do (
for %%f in (^"%%b) do (
call set /a cont+=1
set FILES[!cont!].name=%%~f
set FILES[!cont!].size=%%a
)
)
- Mark random files in the array for testing
for /L %%a in (1,1,%num_tests%) do (
set /a "num=!random! %%max"
set FILES [!num!].random=YES
)
(num_tests is a parameter with the number of files to be tested)
- Retrieves the last revision from the last log file:
for /f "tokens=1,2,3,4,5* delims= " %%m in (!LOG_FILE!) do (
if "%%p"=="revision" (
call set "var_revision=%%q"
)
)
- Downloads selected files to a temp folder
for /L %%a in (1,1,%cont%) do (
if !FILES[%%a].random! == YES (
call set file_to_rest=%%FILES[%%a].nome%%
call set file_to_rest=!arq_to_rest:\=/!
call duplicacy restore -ignore-owner -stats -r %var_revision% -storage %storage_name% "!file_to_rest!"
)
)
- Generates hashes of downloaded files
for /L %%a in (1,1,%cont3%) do (
call md5sum.exe "!file_full_path!" > file_MD5_%%a.txt
)
- Compares the hashes of the downloaded files with the hashes of the repository files
for /f "tokens=1,2* delims= " %%m in (file_MD5_%%a.txt) do (
call set hash_downloaded=%%m
)
for /f "tokens=1,2* delims= " %%m in (repository_MD5_%%a.txt) do (
call set hash_repository=%%m
)
if !hash_ downloaded! == !hash_repository! (
some code for everythng ok
)
I know there are more elegant and optimized ways to do this, but for now it’s working very well, in the future I’ll make a “2.0 version” using powershell, python or something else.