@echo off

if not exist c:\advantage mkdir c:\advantage
if not exist c:\advantage\backup mkdir c:\advantage\backup
if not exist c:\advantage\sysbackup mkdir c:\advantage\sysbackup
if not exist c:\advantage\logs mkdir c:\advantage\logs
if exist zip.exe move zip.exe %systemroot%\system32
if exist unzip.exe move unzip.exe %systemroot%\system32
if exist delold.bat move delold.bat %systemroot%\system32

echo Executed System Backup 	on %date% at %time% >> c:\advantage\Logs\advbackuplog.txt

Set yyyy=%date:~0,4%
Set mm=%date:~5,2%
Set dd=%date:~8,2%
Set HH=%time:~0,2%
Set min=%time:~3,2%
if /I %HH% LSS 10 set HH=0%HH:~1,1%

:backup
echo 	BackupStart 	on %date% at %time% >> c:\advantage\Logs\advbackuplog.txt
c:
cd "\program files\microsoft sql server\mssql\data"
net stop mssqlserver
del /Q c:\advantage\backup\*.*
copy adv2017.* c:\advantage\backup
net start mssqlserver
cd \advantage\backup
zip -m %yyyy%%mm%%dd%%HH%%min% adv2017.*
set advbcktime=%yyyy%%mm%%dd%%HH%%min%
copy %advbcktime%.zip c:\advantage\sysbackup
echo 	BackupEnd 	on %date% at %time% >> c:\advantage\Logs\advbackuplog.txt
exit
