REM http://stackoverflow.com/questions/122690/what-is-a-simple-command-line-program-or-script-to-backup-sql-server-databases
REM "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\osql.exe" -E -Q "BACKUP DATABASE mydatabase TO DISK='D:\db.bak' WITH FORMAT"

SET INSTANCE=(local)\Instance
SET databaseName=CaptureThis_{KundenName}
SET targetPath=C:\CADOSYS\DB^&ST\

set hr=%time:~0,2%
if "%hr:~0,1%" equ " " set hr=0%hr:~1,1%
SET postFix=%date:~-4,4%%date:~-7,2%%date:~-10,2%_%hr%%time:~3,2%%time:~6,2%
echo %postFix%
REM yyyyMMDD_HHmmss

osql.exe -S %INSTANCE% -U CADOSYS -P CadoSqlPass -Q "BACKUP DATABASE [%databaseName%] TO DISK='%targetPath%%databaseName%_%postFix%_Database.bak' WITH FORMAT"
REM osql.exe -S %INSTANCE% -E -Q "BACKUP DATABASE %databaseName% TO DISK='%targetPath%%databaseName%_%postFix%_Database.bak' WITH FORMAT"
@echo EXIT_CODE of Backup: %ERRORLEVEL%
IF %ERRORLEVEL% NEQ 0 (
  @ECHO Backup fehlerhaft: '%ERRORLEVEL%'!!!
  @COLOR 0C
  @pause
  @exit /B 1
) ELSE (
  @COLOR 0A
  @ECHO Backup erfolgreich!!!
)
REM Compress:
"C:\Program Files\7-Zip\7z" a %databaseName%_%postFix%_Database.7z %databaseName%_%postFix%_Database.bak
REM del %databaseName%_%postFix%_Database.bak

echo Fenster wird in 5 Sekunden geschlossen.
@ping localhost -n 5 >NUL
@exit
