Advertisement
Guest User

install script

a guest
Apr 14th, 2015
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 7.61 KB | None | 0 0
  1. :: installSP.bat
  2. :: Written by Rich Johnson for StorageCraft
  3. :: Last modified 2014-12-15
  4.  
  5. :: This script is processed by all internal workstations and servers.  It determines
  6. :: if a backup location exists, and creates one if not.  It then determines if
  7. :: ShadowProtect is up to date, and updates if not.  It then calls the script to create
  8. :: the backup job.
  9.  
  10. :: TODO - If the destination folder is deleted, but the job still exists in SP, a new destination
  11. ::        may be created that is different than the job.
  12.  
  13. @echo off
  14.  
  15. :: logging overrides each previous log so it doesn't grow out of control
  16. set logLocation="C:\ProgramData\installSP.log"
  17. echo %date% %time% - New log file created > %logLocation%
  18. echo . . . >> %logLocation%
  19. echo NOTE - use this file in conjunction with the main ShadowProtect install log to troubleshoot installation issues. >> %logLocation%
  20. echo NOTE - this file is located at C:\Program Files (x86)\StorageCraft\ShadowProtect\Logs. >> %logLocation%
  21. echo . . . >> %logLocation%
  22.  
  23. :: Receive the parameters passed in by the scheduled task
  24. set platform=%1
  25. echo %date% %time% - This is a %platform%. >> %logLocation%
  26.  
  27. :: Determine IP address of host system.  IP address determines where the host system is located.
  28. :: Backup destinations are different for hosts in different locations.
  29. ::FOR /F "tokens=2,3" %%A IN ('ping %computername% -n 1 -4') DO IF "from"== "%%A" set "IP=%%~B"
  30. ::set ipAddress=%IP:~0,-1%
  31. ::set host=Utah
  32.  
  33. ::if not x%ipaddress:172.16=%==x%ipaddress% (
  34. ::  set host=Ireland
  35. ::  echo %date% %time% - This is an Ireland system. >> %logLocation%
  36. ::)
  37. ::if not x%ipaddress:172.16.1.=%==x%ipaddress% (
  38. ::  set host=Portugal
  39. ::  echo %date% %time% - Haha, JK! This is a Portugal system. >> %logLocation%
  40. ::)
  41.  
  42. :: Set destination backup server depending on %ipaddress% and %platform% variables above
  43. if %platform%==WKS (
  44.     set server=server-name
  45.     set serial=<redacted because you cant have our serial number!>
  46. )
  47. if %platform%==Server (
  48.     set server=server-name
  49.     set serial=<redacted because you cant have our serial number!>3
  50. )
  51. echo %date% %time% - Backup server will be %server%. >> %logLocation%
  52.  
  53. :: Check if a backup destination already exists.  If it does, skip to the setBackup subroutine
  54. set dExists=0
  55. echo %date% %time% - Looking for backup destination... >> %logLocation%
  56.  
  57. if exist "\\%server%\small\%COMPUTERNAME%" (
  58.     set dExists=1
  59.     set backupPath="\\%server%\small\%COMPUTERNAME%"
  60.     echo %date% %time% - Destination found on Small. >> %logLocation%
  61. )
  62.  
  63. if exist "\\%server%\large\%COMPUTERNAME%" (
  64.     set dExists=1
  65.     set backupPath="\\%server%\large\%COMPUTERNAME%"
  66.     echo %date% %time% - Destination found on Large. >> %logLocation%
  67. )
  68.  
  69. if %dExists%==1 (
  70.     echo %date% %time% - Destination already exists.  Skipping destination creation... >> %logLocation%
  71.     goto setBackup
  72. )
  73.  
  74. echo %date% %time% - Destination does not exist on small or large.  Will create...
  75.  
  76. :: Number file does not exist so we need to create it
  77. set numberfile="\\%server%\small\number.txt"
  78. if not exist %numberfile% (
  79.     echo %date% %time% - numberfile does not exist, or permissions are incorrect. >> %logLocation%
  80.     goto done
  81. ) else (
  82.     echo %date% %time% - numberFile does exist. >> %logLocation%
  83. )
  84. goto searchNumberFile
  85.  
  86. :: Check the number file.  Depending on the value (1, 2, or 3) the backup destination could be
  87. :: created on the small share or the large share.  Since the large share is 2/3 the disk size
  88. :: of the total shared space, if the number is 2 or 3, the destination will be large.  If the
  89. :: number is 1, then the destination is small (since small is 1/3 the total share size).
  90. :searchNumberFile
  91. echo %date% %time% - Entered the searchNumberFile subroutine. >> %logLocation%
  92. findstr /m "1" %numberfile%
  93. if %errorlevel%==0 (
  94.     echo %date% %time% - numberFile contains a 1.  Will set Destination to small... >> %logLocation%
  95.     if not exist \\%server%\small\%COMPUTERNAME% (
  96.         echo %date% %time% - Destination does not currently exist.  Will create... >> %logLocation%
  97.         md \\%server%\small\%COMPUTERNAME%
  98.         icacls \\%server%\small\%COMPUTERNAME% /grant:r "domain\%COMPUTERNAME%$:(OI)(CI)(RX,W)" /T
  99.         set backupPath=\\%server%\small\%COMPUTERNAME%
  100.         if exist \\%server%\small\%COMPUTERNAME% (
  101.             echo %date% %time% - Destination created successfully! >> %logLocation%
  102.         ) else (
  103.             echo %date% %time% - There was a problem creating destination! >> %logLocation%
  104.             goto done
  105.         )
  106.     )
  107.     echo 2 > %numberfile%
  108.     goto setBackup
  109. )
  110.  
  111. findstr /m "2" %numberfile%
  112. if %errorlevel%==0 (
  113.     echo %date% %time% - numberFile contains a 2.  Will set Destination to large... >> %logLocation%
  114.     if not exist \\%server%\large\%COMPUTERNAME% (
  115.         echo %date% %time% - Destination does not currently exist.  Will create... >> %logLocation%
  116.         md \\%server%\large\%COMPUTERNAME%
  117.         icacls \\%server%\large\%COMPUTERNAME% /grant:r "domain\%COMPUTERNAME%$:(OI)(CI)(RX,W)" /T
  118.         set backupPath=\\%server%\large\%COMPUTERNAME%
  119.         if exist \\%server%\large\%COMPUTERNAME% (
  120.             echo %date% %time% - Destination created successfully! >> %logLocation%
  121.         ) else (
  122.             echo %date% %time% - There was a problem creating destination! >> %logLocation%
  123.             goto done
  124.         )
  125.     )
  126.     echo 3 > %numberfile%
  127.     goto setBackup
  128. )
  129.  
  130. findstr /m "3" %numberfile%
  131. if %errorlevel%==0 (
  132.     echo %date% %time% - numberFile contains a 3.  Will set Destination to large... >> %logLocation%
  133.     if not exist \\%server%\large\%COMPUTERNAME% (
  134.         echo %date% %time% - Destination does not currently exist.  Will create... >> %logLocation%
  135.         md \\%server%\large\%COMPUTERNAME%
  136.         icacls \\%server%\large\%COMPUTERNAME% /grant:r "domain\%COMPUTERNAME%$:(OI)(CI)(RX,W)" /T
  137.         set backupPath=\\%server%\large\%COMPUTERNAME%
  138.         if exist \\%server%\large\%COMPUTERNAME% (
  139.             echo %date% %time% - Destination created successfully! >> %logLocation%
  140.         ) else (
  141.             echo %date% %time% - There was a problem creating destination! >> %logLocation%
  142.             goto done
  143.         )
  144.     )
  145.     echo 1 > %numberfile%
  146.     goto setBackup
  147. )
  148.  
  149. :: For some reason, maybe the number file doesn't have a 1, 2, or 3 in it, so we need to set it,
  150. :: then we need to start over at the serachNumberFile subroutine
  151. echo %date% %time% - Did not find a 1, 2, or 3 in the numberFile!  Check permissions. >> %logLocation%
  152. echo 1 > %numberfile%
  153. quit
  154. goto searchNumberFile
  155.  
  156. :setBackup
  157. echo %date% %time% - Entered the setBackup subroutine... >> %logLocation%
  158. ::Check if upgrade or installation is needed
  159. echo %date% %time% - Determining if upgrade or installation is needed... >> %logLocation%
  160. pushd \\file-server\scripts
  161. cscript installSP-CompairVersions.vbs
  162. if %errorlevel%  EQU 5 (
  163.     echo %date% %time% - Version is less than version posted on the server.  Will install newer version. >> %logLocation%
  164.     popd
  165.     goto install
  166. )
  167. if %errorlevel% EQU 4 (
  168.     echo %date% %time% - Version is greater than or equal to version posted on the server.  Will not install/upgrade. >> %logLocation%
  169.     popd
  170.     goto createJob
  171. )
  172.  
  173. ::Install ShadowProtect
  174. :install
  175. echo %date% %time% - Entered the install subroutine... >> %logLocation%
  176. popd
  177. pushd \\file-server\scripts\shadowprotect
  178. shadowprotectsetup.exe install IACCEPT=STORAGECRAFT.EULA lang=en SERIAL=%serial% USER=%COMPUTERNAME% ORGANIZATION=STC
  179. popd
  180. goto createJob
  181.  
  182. ::Create the backup job
  183. :createJob
  184. echo %date% %time% - Entered the createJob subroutine. >> %logLocation%
  185. pushd \\file-server\scripts
  186. cscript installSP-CreateBackupJob.vbs %backupPath% %platform%
  187. echo %date% %time% - Returning from the installSP-CreateBackupJob.vbs script. >> %logLocation%
  188. popd
  189. goto done
  190.  
  191. :done
  192. echo %date% %time% - Exiting. >> %logLocation%
  193. :: exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement