Posts tagged ‘backup’

16/11/2010

Automatic MSSQL 2008 Backup Batchfile

I was asked to create a simple process for backups to a MSSQL database. After a little searching around online I came up with a Windows batchfile, and then used scheduled tasks to run it weekly:

set ToDaysDate=%date:~3,2%%date:~0,2%%date:~6,4%

"C:\Program Files\Microsoft SQL Server\90\Tools\binn\sqlcmd.exe" -U sa -P
Password -S .\INSTANCENAME -Q "BACKUP DATABASE DatabaseName TO
DISK='C:\Backups\DatabaseName%ToDaysDate%.bak' WITH FORMAT"

This saves a backup file in the folder you specify with the data appended – i.e. DatabaseName161110.bak