Guest User

Untitled

a guest
Feb 14th, 2012
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rem ***AGE IS A STATE OF MIND***
  2. rem Updated Log Copy tool started 8/16/11
  3. @echo off
  4. :globalVars
  5. rem ~~~~~~~~~~~~~~Global VARS~~~~~~~~~~~~~~~~~~~~
  6. set arg1=%1
  7. if %1 == autorun (
  8. call set auto=copy
  9. ) else (
  10. call set auto=no
  11. )
  12. set daydate=%date:~12,2%%date:~4,2%%date:~7,2%
  13. set pyy=%date:~12,2%
  14. rem Daydate is a 2digit yymmdd
  15. set YYYY=%date:~10,4%
  16. rem For dynamic folder pathing.
  17. rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. set deleteOK=0
  19. set deleteLIM=0
  20. rem Count lines to set deleteOK ceiling
  21. FOR /f "eol=[ tokens=1 delims=~" %%K IN (sources.txt) DO (
  22. set /a deleteLIM+=1
  23. )
  24. echo %deleteLIM%
  25. rem SETLOCAL DISABLEDELAYEDEXPANSION
  26. SETLOCAL ENABLEDELAYEDEXPANSION
  27. rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28. :froty
  29. rem froty=FirstRunOfTheYear
  30. set yy=%date:~10,4%
  31. rem The next few lines do the following: Test for the existance of file corresponding to the current year.
  32. rem The year is in yyyy format, using yy as var (don't want to overload yyyy too much and get discombobulated.)
  33. rem
  34. if NOT exist "%appdata%\WebTrends\%yy%.y" (
  35. set /a yyyy-=1
  36. set /a pyy-=1
  37. echo First run of the year.
  38. echo %yy% > "C:\Documents and Settings\aps-svc\Application Data\WebTrends\%yy%.y"
  39. pause
  40. del /f /q paths.txt
  41. del /f /q newdirectories.txt
  42. FOR /f "eol=[ tokens=2 delims=~" %%P IN (sources.txt) DO (
  43. CALL echo %%P >> paths.txt
  44. )
  45. FOR /f "tokens=1,2,3,4 delims=\" %%A IN (paths.txt) DO (
  46. CALL echo Creating \\%%A\%%B\%%C\%%D\reports\2012 >> newdirectories.txt
  47. CALL mkdir \\%%A\%%B\%%C\%%D\reports\2012
  48. )
  49. del /f /q paths.txt
  50. goto copy
  51. ) else (
  52. set pyy=%date:~12,2%
  53. echo Not first run of the year. >> "D:\BATCH\Excludes_%daydate%.txt" && goto start
  54. )
  55.  
  56. :start
  57. if exist D:\BATCH\copylogv2*.* (
  58. echo Copylog exists in directory for previous run. Please move to the correct directory
  59. pause
  60. goto start
  61. )
  62. TITLE ~~~~WEBTRENDS Log copy utility v2~~~~
  63. cls
  64. rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65. rem FOR loop vars use and assignment:
  66. rem %%D - Used for 1st "Column" in sources.txt - Path of server\folder where files are to be deleted. Used in pulling attrib flag.
  67. rem %%E - Excludes file for XCOPY - Used against 1st "column" in sources.txt
  68. rem %%K - Delete comparison "deleteLIM". The deleteOK var must match this to delete files. - Used against 1st "column" in sources.txt
  69. rem %%A - Used for 1st "Column" in sources.txt - This is the files SOURCE server\path
  70. rem %%B - Used for 2nd "Column" in sources.txt - This is the files DESTINATION server\path
  71. rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. :sourcesmenu
  73. cls
  74. if %auto% == copy (
  75. goto COPY
  76. ) else (
  77. if %auto% == delete (
  78. goto deletetest
  79. )
  80. )
  81. color 0a
  82. echo Please select which server to copy from:
  83. echo 1. To COPY files from WEB servers to ANALYTICS server (PSIWebtrend1)
  84. echo D. For delete routine. Will only run after copy.
  85. echo Q. To quit!
  86. set INPUT=
  87. set /p INPUT=Choice:
  88. if /I '%INPUT%'=='1' goto COPY
  89. if /I '%INPUT%'=='D' goto deletetest
  90. if /I '%INPUT%'=='Q' goto quit
  91. if /I '%INPUT%' NEQ '1' goto sourcesmenu
  92. if /I '%INPUT%' NEQ 'D' goto sourcesmenu
  93. if /I '%INPUT%' NEQ 'Q' goto sourcesmenu
  94. rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. rem set rancopy=1 (This is counter for access to log delete system. Instantiating errorlevel based access)
  96. rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  97. rem The idea of this script is to be run with 2
  98. rem options. 1: Copy all logs. 2: Delete all logs.
  99. rem Copy all logs should operate something to the
  100. rem effect of regard "sources.txt" (text document).
  101. rem Parse this list file and use the path with the
  102. rem daydate (which is actually used to EXCLUDE the
  103. rem current day marked file) and copy all files from
  104. rem all sources to all destinations, excluding the
  105. rem current day file and ANY folders.
  106. rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  107. rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  108. rem THE FOR LOOP. Parses log. Each folder on the
  109. rem source server will need server path and then folder name
  110. rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. :COPY
  112. FOR /f "eol=[ tokens=1 delims=~" %%E IN (sources.txt) DO (
  113. CALL dir /b /ad "%%E" >> "D:\BATCH\Excludes_%daydate%.txt"
  114. CALL dir /b "%%E\*%daydate%*" >> "D:\BATCH\Excludes_%daydate%.txt"
  115. )
  116. echo Please Wait...
  117. FOR /f "eol=[ tokens=1,2 delims=~" %%A IN (sources.txt) DO (
  118. rem CALL echo SOURCE %%A For the following. >> "D:\BATCH\copylogv2_%daydate%.txt"
  119. CALL xcopy "%%A\*ex%pyy%*" "%%B\" /EXCLUDE:D:\BATCH\Excludes_%daydate%.txt /Z /F /D /E /Y >> "D:\BATCH\copylogv2_%daydate%.txt"
  120. if NOT ERRORLEVEL 0 (
  121. set /a deleteOK-=1
  122. ) else (
  123. set /a deleteOK+=1
  124. )
  125. )
  126. echo %deleteOK%
  127. pause
  128. if %yy% GTR %yyyy% (
  129. echo.
  130. echo %YYYY% final copy complete... Starting %yy% initial copy.
  131. echo.
  132. echo RERUNNING FOR NEW YEAR...
  133. set /a yyyy+=1 && set /a pyy+=1 && goto COPY
  134. ) else (
  135. if %auto% == copy (
  136. set auto=delete & goto sourcesmenu
  137. ) else (
  138. goto sourcesmenu
  139. )
  140. :deletetest
  141. if '%deleteOK%'=='%deleteLIM%' (
  142. goto deleteFiles
  143. ) else (
  144. set deleteOK=0
  145. echo There were errors on the copy. Please examine copylogv2_%daydate%.txt for failed copies.
  146. pause & goto sourcesmenu
  147. )
  148. :deleteFiles
  149. color CF
  150. FOR /f "eol=[ tokens=1 delims=~" %%D IN (sources.txt) DO (
  151. CALL attrib -a "%%D\*%daydate%*"
  152. CALL del /q /aa "%%D\"
  153. CALL attrib +a "%%D\*%daydate%*"
  154. )
  155. echo success
  156. pause & goto sourcesmenu
  157. :movelogs
  158. set MM=%date:~4,2%
  159. if %MM%==01 set MM=January
  160. if %MM%==02 set MM=February
  161. if %MM%==03 set MM=March
  162. if %MM%==04 set MM=April
  163. if %MM%==01 set MM=May
  164. if %MM%==02 set MM=June
  165. if %MM%==03 set MM=July
  166. if %MM%==04 set MM=August
  167. if %MM%==01 set MM=September
  168. if %MM%==02 set MM=October
  169. if %MM%==03 set MM=November
  170. if %MM%==04 set MM=December
  171. rem
  172. if NOT exist D:\BATCH\%MM%_%YYYY% (
  173. mkdir %MM%_%YYYY% & move /y copylog*.* %MM%_%YYYY%\
  174. ) else (
  175. move /y D:\BATCH\copylog*.* D:\BATCH\%MM%_%YYYY%
  176. )
  177. :errors
  178. echo Your current error level is %ERRORLEVEL%
  179. echo If it is 0 there were no problems.
  180. echo If it is 1 there were problems, review logs.
  181. echo Log will be found in %MM%_%YYYY%
  182. pause
  183. :QUIT
  184. color 07
Advertisement
Add Comment
Please, Sign In to add comment