This script takes full backups of SQL databases, stores the reports, and emails the results. This script makes use of ExpressMaint for backups and Bmail to send emails.

@echo off
:: set some stuff
SET utilBaseDir=C:\util
SET backupBaseDir=C:\db-backups
SET reportBaseDir=C:\db-reports
SET [email protected]
SET [email protected]
SET useEmailServer=smtp.contoso.com
SET mailServerPort=25

:: backup the db
%utilBaseDir%\ExpressMaint.exe -S (local) -D ALL -B %backupBaseDir% -BU Days -BV 14 -V -C -RU Days -RV 14 -R %reportBaseDir% -T DB

:: get most recent report file
FOR /F "delims=|" %%I IN ('DIR "%reportBaseDir%\*.*" /B /O:D') DO SET NewestFile=%%I

:: get current date
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET dbReportDate=%mm%-%dd%-%yyyy%

:: email report
%utilBaseDir%\bmail.exe -s %useEmailServer% -p %mailServerPort% -t %reportEmailTo% -f %reportEmailFrom% -a "%dbReportDate% - Backup Report" -m %reportBaseDir%\%newestfile%