Posted By

CynderR on 11/13/10


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

thastyle
bug5
abumap


backup.bat


 / Published in: DOS Batch
 

  1. @ECHO OFF
  2. CLS
  3. GOTO skipcomment
  4. REM its been awhile since i wrote VB or BAT files
  5. REM automate.vbs calls this file (i read it was a good way to have the backup run silently )
  6. REM %1 is the dir tree (e: or c: or whatever)
  7. REM %2 is the site name (Also the root folder in the dir tree)
  8. REM %3 is the path to repozo (shouldnt change...)
  9. REM %4 is the backup path for the backup
  10.  
  11. :skipcomment
  12. REM Note:these are TEMP var's, there contents change often
  13. SET folder=%date:~10,4%-%date:~4,2%-%date:~7,2%
  14. SET return=empty
  15.  
  16. SET mkfolder=%4\%folder%\
  17. SET /a count=0
  18.  
  19. SET logFolder=%4\log\%folder%.log
  20. REM if testing is set to true, skip commands i know that are working.
  21. SET testing=False
  22. SET debugLine2=I-------------------------------------------------------------------------------------------------------------------I
  23. SET debugLine3=I-------------------------------------------------------------------------------------------------------------------I
  24. SET debugLine4=I-------------------------------------------------------------------------------------------------------------------I
  25. SET debugEmpty=I-------------------------------------------------------------------------------------------------------------------I
  26. SET debugEnd=L-------------------------------------------------------------------------------------------------------------------J
  27.  
  28. REM check Root folder
  29. IF NOT EXIST %4\log\ MKDIR %4\log\
  30. REM Log data passed by the VB script (automate.vbs)
  31. GOTO logParams
  32. :logParamsEnd
  33.  
  34. SET debugLine2= Running in Verbose mode
  35. SET debug=debug1
  36. GOTO debug
  37. :debug1
  38.  
  39. SET return=roboFolderLog
  40. SET folder=%4\roboBackup
  41. GOTO doesFolderExists
  42. :roboFolderLog
  43.  
  44. SET return=roboFolder
  45. SET folder=%4\roboBackup\data
  46. GOTO doesFolderExists
  47. :roboFolder
  48.  
  49. REM .this Script location
  50. SET scriptDir=%CD%
  51.  
  52. REM DEBUG
  53. SET debugLine2="Call repozo with B backup, v verbose, z compressed, --r Backup Location, --f File Location"
  54. SET debugLine3= "%1%2%3 -Bvz -r %4 -f %1%2\var\filestorage\Data.fs"
  55. SET debug=debug2
  56. GOTO debug
  57. :debug2
  58. REM DEBUG END
  59.  
  60. REM LOG
  61. ECHO. >>%logFolder%
  62. ECHO.REM call repozo (B = backup, v=verbose, z=compressed, -r=Backup Location, -f=File Location)>>%logFolder%
  63. ECHO.%Time% Start: %1%2%3 -Bvz -r %4 -f %1%2\var\filestorage\Data.fs >>%logFolder%
  64. IF %testing%== False %1%2%3 -Bvz -r %4 -f %1%2\var\filestorage\Data.fs >>%logFolder%
  65. REM LOG
  66. ECHO.%Time% End: %1%2%3 -Bvz -r %4 -f %1%2\var\filestorage\Data.fs >>%logFolder%
  67. ECHO. >>%logFolder%
  68.  
  69. REM LOG
  70. ECHO.%Time% : Current directory changed from %CD% to %4 >>%logFolder%
  71. REM Backup folder
  72. CD %4
  73.  
  74.  
  75.  
  76. REM DEBUG
  77. SET debugLine2= Creating directory if not exists
  78. SET debugLine3= %mkfolder%
  79. SET debug=debug3
  80. GOTO debug
  81. :debug3
  82. REM DEBUG END
  83.  
  84.  
  85.  
  86.  
  87. SET roboLogName=ROBOCopy%date:~10,2%%date:~4,2%%date:~7,2%
  88. IF NOT %testing%== False GOTO skip
  89. REM Copyall=Copy all file info(users
  90. REM E= copy files and folders(empty ones too)
  91. REM R= retry 3 times if copy fails
  92. REM w= wait 20sec before trying again or moving on
  93. REM dcopy= keep origonal timestamp
  94. REM v= show data (verbose)
  95. REM np= No Progress bar
  96. REM log= output data to the log file
  97. REM XF= exclude file
  98. REM m= only backup changed files.
  99.  
  100. REM DEBUG
  101. SET debugLine2=Copy all Site files to the backup location
  102. SET debugLine3="ROBOCOPY %1%2 %4\roboBackup\data /E /R:3 /W:20 /DCOPY:T /XF Data.fs /A /V /NP /LOG:%4\log\%roboLogName%.log"
  103. SET debugLine4="Log file located at : %4\log\%roboLogName%.log"
  104. SET debug=debug4
  105. GOTO debug
  106. :debug4
  107. REM DEBUG END
  108. IF %5 == False GOTO quickpass
  109. ROBOCOPY %1%2 %4\roboBackup\data /E /R:3 /W:20 /DCOPY:T /XF Data.fs /A /V /NP /LOG:%4\log\%roboLogName%.log
  110. GOTO skip
  111. :quickpass
  112. ROBOCOPY %1%2 %4\roboBackup\data /E /R:1 /W:0 /DCOPY:T /V /XF Data.fs /A /NP /LOG:%4\log\%roboLogName%.log
  113. :skip
  114. REM DEBUG
  115. ECHO.%Time% : Done! >>%logFolder%
  116. SET debugLine2= All Done!
  117. SET debug=debug6
  118. GOTO debug
  119. :debug6
  120. REM DEBUG END
  121.  
  122. REM LOG
  123. ECHO.=================== >>%logFolder%
  124. ECHO.^^^^^^^^^^^^^^ END ^^^^^^^^^^^^ >>%logFolder%
  125. ECHO. >>%logFolder%
  126. ECHO. >>%logFolder%
  127. ECHO. >>%logFolder%
  128. ECHO. >>%logFolder%
  129. GOTO end
  130.  
  131. REM ----------------------------------------------
  132. REM J's fun_ctions
  133. REM ----------------------------------------------
  134. REM Check Folder exists
  135. :doesFolderExists
  136. IF NOT EXIST %folder% GOTO createFolder
  137. GOTO %return%
  138.  
  139. REM ----------------------------------------------
  140. REM CREATE FOLDER
  141. :createFolder
  142. MKDIR %folder% >>%logFolder%
  143. ECHO.%Time% : Create this folder >>%logFolder%
  144. ECHO.%Time% : %folder% >>%logFolder%
  145. GOTO %return%
  146.  
  147. REM ----------------------------------------------
  148. REM DEBUG
  149. :debug
  150. REM put this in the log file
  151. REM VV VV VV VV VV VV VV VV VV VV
  152. SET /a count=%count%+1
  153. SET debugLine1=r----------------------------------------- NOTE: %count% At: %Time% -----------------------------------------------,
  154. ECHO. >>%logFolder%
  155. ECHO.I%debugLine1% >>%logFolder%
  156. ECHO.I%debugLine2% >>%logFolder%
  157.  
  158. IF NOT %debugLine3% == %debugEmpty% ECHO.I%debugLine3% >>%logFolder%
  159. IF NOT %debugLine4% == %debugEmpty% ECHO.I%debugLine4% >>%logFolder%
  160. ECHO.%debugEnd% >>%logFolder%
  161. ECHO. >>%logFolder%
  162. ECHO. >>%logFolder%
  163. REM VV VV VV VV VV VV VV VV VV VV VV VV VVV
  164. REM DEBUG MODE: Put this on the screen VV
  165. REM VV VV VV VV VV VV VV VV VV VV VV VV VVV
  166. IF %5 == False (
  167. CLS
  168. ECHO.
  169. ECHO.I%debugLine1%
  170. ECHO.I%debugLine2%
  171. IF NOT %debugLine3% == %debugEmpty% ECHO.I%debugLine3%
  172. IF NOT %debugLine4% == %debugEmpty% ECHO.I%debugLine4%
  173. ECHO.%debugEnd%
  174. ECHO.
  175. REM NOTE: This is the only pause in the script (or this script cant be automated)
  176. )
  177. REM ^ ^^ ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^^^
  178. REM ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^
  179. REM ^ ^^ ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^^^
  180. REM clear data
  181. SET debugLine4= %debugEmpty%
  182. SET debugLine3= %debugEmpty%
  183. SET debugLine2= %debugEmpty%
  184. GOTO %debug%
  185.  
  186. REM ----------------------------------------------
  187. REM GET OUT OF MY HEAD(er)!!!!
  188. REM ----------------------------------------------
  189. REM Note: Not a fucntion.
  190. :logParams
  191. ECHO. >>%logFolder%
  192. ECHO.vvvvvv START vvvvvv >>%logFolder%
  193. ECHO.=================== >>%logFolder%
  194. ECHO.I VBS Params I >>%logFolder%
  195. ECHO.=================== >>%logFolder%
  196. ECHO.Ran on:%Date% >>%logFolder%
  197. ECHO. At:%Time% >>%logFolder%
  198. ECHO. >>%logFolder%
  199. ECHO. Log file path : %mkfolder% >>%logFolder%
  200. ECHO.Drive Letter / Location : %1 >>%logFolder%
  201. ECHO. Site : %2 >>%logFolder%
  202. ECHO. Path to REPOZE : %1%2%3 >>%logFolder%
  203. ECHO. Backup Folder Path : %4 >>%logFolder%
  204. ECHO.shhhhsshh!(run Quitely) : %5 >>%logFolder%
  205. ECHO. >>%logFolder%
  206. ECHO.=================== >>%logFolder%
  207. ECHO. >>%logFolder%
  208. ECHO. >>%logFolder%
  209. GOTO logParamsEnd
  210.  
  211. REM ----------------------------------------------
  212. REM end fun_ctions
  213. REM ----------------------------------------------
  214.  
  215. :end

Report this snippet  

You need to login to post a comment.