@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 Manual Backup 	on %date% at %time% >> c:\advantage\Logs\advbackuplog.txt

echo %date% %time% > e:\ns
if not exist e:\ns goto nodisk
del /Q e:\ns

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%

if exist c:\advantage\backup\%yyyy%%mm%%dd%%HH%%min%.zip goto warning

:Backup
echo 	BackupStart 	on %date% at %time% >> c:\advantage\Logs\advbackuplog.txt
c:
cd "\program files\microsoft sql server\mssql\data"
del /Q c:\advantage\backup\*.*
net stop mssqlserver
copy adv2017.* c:\advantage\backup
net start mssqlserver
cd \advantage\backup
set advbcktime=%yyyy%%mm%%dd%%HH%%min%
zip -m %yyyy%%mm%%dd%%HH%%min% adv2017.*
echo.
echo.
Zip -T %advbcktime%.zip
echo.
echo.
copy %advbcktime%.zip c:\advantage\sysbackup
copy %advbcktime%.zip e:
e:
echo These files have been backed up succesfully.
unzip -l %advbcktime%.zip
pause

cls
call delold.bat 5

echo 	BackupEnd 	on %date% at %time% >> c:\advantage\Logs\advbackuplog.txt
exit

:Warning
color 47
echo You have already run a backup within the last minute, if you do NOT want to continue press ctrl+c, otherwise press any key
pause
goto backup

:nodisk
cls
color 47
echo No Flash Disk in drive 	on %date% at %time% >> c:\advantage\Logs\advbackuplog.txt
echo Drive e: does not exist, you probably do not have your flash disk in.
echo Please insert your flash disk and run the backup again.
pause
color 07
exit