Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: installSP.bat
- :: Written by Rich Johnson for StorageCraft
- :: Last modified 2014-12-15
- :: This script is processed by all internal workstations and servers. It determines
- :: if a backup location exists, and creates one if not. It then determines if
- :: ShadowProtect is up to date, and updates if not. It then calls the script to create
- :: the backup job.
- :: TODO - If the destination folder is deleted, but the job still exists in SP, a new destination
- :: may be created that is different than the job.
- @echo off
- :: logging overrides each previous log so it doesn't grow out of control
- set logLocation="C:\ProgramData\installSP.log"
- echo %date% %time% - New log file created > %logLocation%
- echo . . . >> %logLocation%
- echo NOTE - use this file in conjunction with the main ShadowProtect install log to troubleshoot installation issues. >> %logLocation%
- echo NOTE - this file is located at C:\Program Files (x86)\StorageCraft\ShadowProtect\Logs. >> %logLocation%
- echo . . . >> %logLocation%
- :: Receive the parameters passed in by the scheduled task
- set platform=%1
- echo %date% %time% - This is a %platform%. >> %logLocation%
- :: Determine IP address of host system. IP address determines where the host system is located.
- :: Backup destinations are different for hosts in different locations.
- ::FOR /F "tokens=2,3" %%A IN ('ping %computername% -n 1 -4') DO IF "from"== "%%A" set "IP=%%~B"
- ::set ipAddress=%IP:~0,-1%
- ::set host=Utah
- ::if not x%ipaddress:172.16=%==x%ipaddress% (
- :: set host=Ireland
- :: echo %date% %time% - This is an Ireland system. >> %logLocation%
- ::)
- ::if not x%ipaddress:172.16.1.=%==x%ipaddress% (
- :: set host=Portugal
- :: echo %date% %time% - Haha, JK! This is a Portugal system. >> %logLocation%
- ::)
- :: Set destination backup server depending on %ipaddress% and %platform% variables above
- if %platform%==WKS (
- set server=server-name
- set serial=<redacted because you cant have our serial number!>
- )
- if %platform%==Server (
- set server=server-name
- set serial=<redacted because you cant have our serial number!>3
- )
- echo %date% %time% - Backup server will be %server%. >> %logLocation%
- :: Check if a backup destination already exists. If it does, skip to the setBackup subroutine
- set dExists=0
- echo %date% %time% - Looking for backup destination... >> %logLocation%
- if exist "\\%server%\small\%COMPUTERNAME%" (
- set dExists=1
- set backupPath="\\%server%\small\%COMPUTERNAME%"
- echo %date% %time% - Destination found on Small. >> %logLocation%
- )
- if exist "\\%server%\large\%COMPUTERNAME%" (
- set dExists=1
- set backupPath="\\%server%\large\%COMPUTERNAME%"
- echo %date% %time% - Destination found on Large. >> %logLocation%
- )
- if %dExists%==1 (
- echo %date% %time% - Destination already exists. Skipping destination creation... >> %logLocation%
- goto setBackup
- )
- echo %date% %time% - Destination does not exist on small or large. Will create...
- :: Number file does not exist so we need to create it
- set numberfile="\\%server%\small\number.txt"
- if not exist %numberfile% (
- echo %date% %time% - numberfile does not exist, or permissions are incorrect. >> %logLocation%
- goto done
- ) else (
- echo %date% %time% - numberFile does exist. >> %logLocation%
- )
- goto searchNumberFile
- :: Check the number file. Depending on the value (1, 2, or 3) the backup destination could be
- :: created on the small share or the large share. Since the large share is 2/3 the disk size
- :: of the total shared space, if the number is 2 or 3, the destination will be large. If the
- :: number is 1, then the destination is small (since small is 1/3 the total share size).
- :searchNumberFile
- echo %date% %time% - Entered the searchNumberFile subroutine. >> %logLocation%
- findstr /m "1" %numberfile%
- if %errorlevel%==0 (
- echo %date% %time% - numberFile contains a 1. Will set Destination to small... >> %logLocation%
- if not exist \\%server%\small\%COMPUTERNAME% (
- echo %date% %time% - Destination does not currently exist. Will create... >> %logLocation%
- md \\%server%\small\%COMPUTERNAME%
- icacls \\%server%\small\%COMPUTERNAME% /grant:r "domain\%COMPUTERNAME%$:(OI)(CI)(RX,W)" /T
- set backupPath=\\%server%\small\%COMPUTERNAME%
- if exist \\%server%\small\%COMPUTERNAME% (
- echo %date% %time% - Destination created successfully! >> %logLocation%
- ) else (
- echo %date% %time% - There was a problem creating destination! >> %logLocation%
- goto done
- )
- )
- echo 2 > %numberfile%
- goto setBackup
- )
- findstr /m "2" %numberfile%
- if %errorlevel%==0 (
- echo %date% %time% - numberFile contains a 2. Will set Destination to large... >> %logLocation%
- if not exist \\%server%\large\%COMPUTERNAME% (
- echo %date% %time% - Destination does not currently exist. Will create... >> %logLocation%
- md \\%server%\large\%COMPUTERNAME%
- icacls \\%server%\large\%COMPUTERNAME% /grant:r "domain\%COMPUTERNAME%$:(OI)(CI)(RX,W)" /T
- set backupPath=\\%server%\large\%COMPUTERNAME%
- if exist \\%server%\large\%COMPUTERNAME% (
- echo %date% %time% - Destination created successfully! >> %logLocation%
- ) else (
- echo %date% %time% - There was a problem creating destination! >> %logLocation%
- goto done
- )
- )
- echo 3 > %numberfile%
- goto setBackup
- )
- findstr /m "3" %numberfile%
- if %errorlevel%==0 (
- echo %date% %time% - numberFile contains a 3. Will set Destination to large... >> %logLocation%
- if not exist \\%server%\large\%COMPUTERNAME% (
- echo %date% %time% - Destination does not currently exist. Will create... >> %logLocation%
- md \\%server%\large\%COMPUTERNAME%
- icacls \\%server%\large\%COMPUTERNAME% /grant:r "domain\%COMPUTERNAME%$:(OI)(CI)(RX,W)" /T
- set backupPath=\\%server%\large\%COMPUTERNAME%
- if exist \\%server%\large\%COMPUTERNAME% (
- echo %date% %time% - Destination created successfully! >> %logLocation%
- ) else (
- echo %date% %time% - There was a problem creating destination! >> %logLocation%
- goto done
- )
- )
- echo 1 > %numberfile%
- goto setBackup
- )
- :: For some reason, maybe the number file doesn't have a 1, 2, or 3 in it, so we need to set it,
- :: then we need to start over at the serachNumberFile subroutine
- echo %date% %time% - Did not find a 1, 2, or 3 in the numberFile! Check permissions. >> %logLocation%
- echo 1 > %numberfile%
- quit
- goto searchNumberFile
- :setBackup
- echo %date% %time% - Entered the setBackup subroutine... >> %logLocation%
- ::Check if upgrade or installation is needed
- echo %date% %time% - Determining if upgrade or installation is needed... >> %logLocation%
- pushd \\file-server\scripts
- cscript installSP-CompairVersions.vbs
- if %errorlevel% EQU 5 (
- echo %date% %time% - Version is less than version posted on the server. Will install newer version. >> %logLocation%
- popd
- goto install
- )
- if %errorlevel% EQU 4 (
- echo %date% %time% - Version is greater than or equal to version posted on the server. Will not install/upgrade. >> %logLocation%
- popd
- goto createJob
- )
- ::Install ShadowProtect
- :install
- echo %date% %time% - Entered the install subroutine... >> %logLocation%
- popd
- pushd \\file-server\scripts\shadowprotect
- shadowprotectsetup.exe install IACCEPT=STORAGECRAFT.EULA lang=en SERIAL=%serial% USER=%COMPUTERNAME% ORGANIZATION=STC
- popd
- goto createJob
- ::Create the backup job
- :createJob
- echo %date% %time% - Entered the createJob subroutine. >> %logLocation%
- pushd \\file-server\scripts
- cscript installSP-CreateBackupJob.vbs %backupPath% %platform%
- echo %date% %time% - Returning from the installSP-CreateBackupJob.vbs script. >> %logLocation%
- popd
- goto done
- :done
- echo %date% %time% - Exiting. >> %logLocation%
- :: exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement