Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. rem This script archives automatically the mesaage logs from their folders to the X: drive
  2. rem author Henry Barton, GCO hOP - v0.1 17/07/2017
  3.  
  4. @echo off
  5. rem Trying to automate archiving, at 0100 of the 1st day of the month, zip, test, and move compressed files from D:\ to X:\, then delete files off of D:\
  6.  
  7.  
  8.  
  9.  
  10. rem define location where application logs are found. This is called elsewhere in the script as needed.
  11. set homeDirectory=%~f1
  12.  
  13. rem define location where zipped archives are copied to.
  14. set archiveDirectory=%~f2
  15.  
  16. rem echo input and output directories, for debug.
  17. echo homeDirectory is %~f1 >> %logfile%
  18. echo archiveDirectory is %~f2 >> %logfile%
  19.  
  20. rem CD to input directory to get started.
  21. CD /D %homeDirectory%
  22.  
  23.  
  24. rem Step 1: Check date and time
  25.  
  26. echo %DATE%
  27. echo %TIME%
  28.  
  29.  
  30. rem Step 2:count files in folder
  31. rem C:\NotePad++\AutomatingArchiving - testing directory
  32.  
  33. @echo off
  34. SET rootpath=C:\NotePad++\AutomatingArchiving
  35. set cnt_files=0
  36. set cnt_dirs=0
  37. rem count all files in dir and subdirs
  38. for /f %%a in ('dir /s /B /a-d "%rootpath%"') do set /A cnt_files+=1
  39. rem count all folders in dir and subdirs
  40. for /f %%a in ('dir /s /B /ad "%rootpath%"') do set /A cnt_dirs+=1
  41. echo Location: %rootpath%
  42. echo Files: %cnt_files%
  43. echo Directories: %cnt_dirs%
  44.  
  45.  
  46. rem Step 3: Compress files using 7-zip
  47.  
  48. rem This is used from recurseday.bat
  49. :zipProcess
  50. @echo off
  51. rem start in a month folder and loop through the days
  52. for /d /r %%d in (*) do (
  53. rem for each day, change directory to the day
  54. pushd %%d
  55. rem loop through the hours
  56. for /d %%h in (*) do (
  57. rem zip the hour
  58. START "Compressing Backup. DO NOT CLOSE" /belownormal /wait "C:\Program Files\7-Zip\7z.exe" a -tzip "%%h.zip" ".\%%h\*"
  59. )
  60. rem done with the day, change directory back to the month
  61. popd
  62. )
  63. ECHO Zipped file creation completed...
  64.  
  65.  
  66. rem Step 4: Once zipped, each zipped folder needs to be tested to ensure there is no corruption (THIS DOESN'T WORK YET)
  67.  
  68. @echo off
  69. rem Check the integrity of the zipped files
  70.  
  71. rem check all the resulting zip files in this subdirectory for integrity - if any zip files are corrupt, write the filename to the errorlog.
  72. :checkProcess
  73. echo start check process >> %logfile%
  74. set /a p=0
  75. for %%i in (*.log) do set /a p+=1
  76. if %p%==0 ( goto :eof )
  77. for %%i in (*.zip) do (
  78. "C:\Program Files (x86)\7-Zip\7z.exe" t "%%i" >> %logfile%
  79. set ERL=%ERRORLEVEL%
  80. echo "Error level of integrity check: %ERRORLEVEL%" >> %logfile%
  81. if %ERL% NEQ 0 (
  82. echo "Warning: zipfile %%i has failed integrity check" >> %logfile%
  83. call :deletecorrupt %%i
  84. )
  85. rem this function writes an error log to the failure log if the integrity check fails.
  86. rem if the integrity check succeeds, it renames all the .log files that were added to it to .log.old
  87. if %ERL% NEQ 0 ( echo "Warning: zipfile %%i has failed integrity check" >> %failfile% ) else (
  88. call :rename %%i
  89. )
  90. )
  91. goto :eof
  92.  
  93. :rename
  94. echo start rename process >> %logfile%
  95. set thisZip=%1
  96. set thismask=%thisZip:~0,18%
  97. echo this mask: %thisMask% >> %logfile%
  98. echo rename capture is %cd%\%thisMask%*.log" >> %logfile%
  99. ren "%cd%\%thisMask%*.log" %thisMask%*.log.old >> %logfile%
  100. goto :eof
  101.  
  102.  
  103. :deletecorrupt
  104. echo start delete corrupt process >> %logfile%
  105. set thisZip=%1
  106. del /q %homeDirectory%\*%thisZip% >> %logfile%
  107. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement