With the release of TFS 2012 Express edition – TFS is easier than ever to use. There are some limitations compared to the full version – but for the local developer – it’s great. The one restriction worth noting is it installs SQL Express 2012 and is the only supported platform (you can’t use SQL 2012 full version). This makes it a little more difficult to setup a backup plan to ensure your data doesn’t go bye bye in the event of a failure.
For my environment – I have it installed in a VM – and don’t want to back up the whole OS so I scripted (via a batch file) commands to backup and copy the database files out. I also setup my Team City database (continuous integration server) which is on the regular 2012 instance to be backed up as a part of this. The files are copied out to my local Windows Home Server which has an IDrive agent on it that keeps it nice and safe on the internet.
Here is the batch file text for those who would like to use it.
ECHO"Start Time: " %date%%time% >> CopyBackups.log d: cd d:\BackupAutomation sqlcmd -S .\SqlExpress -Q "EXEC BackupTFS">> CopyBackups.log sqlcmd -Q "EXEC BackupTFS">> CopyBackups.log copy"D:\SqlBackups\Tfs_TSBuild.bak"\\WHS\Backups\TFS\Tfs_TSBuild.bak /Y >> CopyBackups.log copy"D:\SqlBackups\Tfs_Configuration.bak"\\WHS\Backups\TFS\Tfs_TSConfiguration.bak /Y >> CopyBackups.log copy"D:\SqlBackups\TeamCity.bak"\\WHS\Backups\TFS\TeamCity.bak /Y >> CopyBackups.log copy"D:\BackupAutomation\BackupTFSDb.bat"\\WHS\Backups\TFS\BackupTFSDb.bat /Y >> CopyBackups.log ECHO"End Time: " %date%%time% >> CopyBackups.log ECHO *************************************************** >> CopyBackups.log
Here is an example of the Stored Procedure (BackupTFS) that I used to create the backups. This was found via Google. I believe the link below is the original author.
http://www.mssqltips.com/sqlservertip/1070/simple-script-to-backup-all-sql-server-databases/
Note that I changed the backup section to overwrite the original file so it would not keep appending.
Also note this will backup all databases that are not in the filter. If you wish to back up only a select few databases – then you need to modify the filter.
USE[master]GOCREATEProcedure[dbo].[BackupTFS]asDECLARE@nameVARCHAR(50) -- database name DECLARE@pathVARCHAR(256) -- path for backup files DECLARE@fileNameVARCHAR(256) -- filename for backup DECLARE@fileDateVARCHAR(20) -- used for file name SET@path='D:\SqlBackups\'DECLARE db_cursor CURSORFORSELECT name FROM master.dbo.sysdatabases WHERE name NOT IN ('master','model','msdb','tempdb') OPEN db_cursor FETCHNEXTFROM db_cursor INTO@nameWHILE@@FETCH_STATUS=0BEGINSET@fileName=@path+@name+'.BAK'BACKUPDATABASE@nameTODISK=@fileNameWITH FORMAT, INIT FETCHNEXTFROM db_cursor INTO@nameENDCLOSE db_cursor DEALLOCATE db_cursor GO