setlocal ENABLEDELAYEDEXPANSION echo off cls echo -- BACKUP DATABASE -- set DATABASENAME=%Evrim_DB :: filename format Name-Date (eg MyDatabase-2009.5.19.bak) @echo off for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%" set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%" set "fullstamp=%YYYY%_%MM%_%DD%_%HH%_%Min%%Sec%" set BACKUPFILENAME=%CD%\%DATABASENAME%_incremental%fullstamp%.diff set SERVERNAME=W2012R2SQL.gurmen.local echo. sqlcmd -E -S %SERVERNAME% -d master -Q "BACKUP DATABASE [%DATABASENAME%] TO DISK = N'%BACKUPFILENAME%' WITH DIFFERENTIAL , RETAINDAYS = 7, NOFORMAT, NOINIT, NAME = N'%DATABASENAME% backup', SKIP, NOREWIND, NOUNLOAD,STATS = 10" echo. sleep 10