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

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

: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
zip -m Backup adv2017.*

echo.
echo.
Zip -T Backup.zip
echo.
echo.
copy backup.zip c:\advantage\sysbackup
copy backup.zip f:
f:
echo These files have been backed up succesfully.
unzip -l Backup.zip
pause
echo 	BackupEnd 	on %date% at %time% >> c:\advantage\Logs\advbackuplog.txt
exit

:nodisk
cls
color 47
echo No Flash Disk in drive 	on %date% at %time% >> c:\advantage\Logs\advbackuplog.txt
echo Drive f: 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