Wednesday, October 9, 2013

SQL Express 2012 Automated Backup Script

SQL Express doesn't come with the SQL Server Agent and so you can not use the Full SQL server backup maintenance plans.  To get around this I am using the following script which is executed once a day by the task scheduler.

sp_BackupDatabases can be found here: http://support.microsoft.com/kb/2019698

database_backup.bat

md c:\temp_database_bak
sqlcmd -S {{MACHINE_NAME}}\SQLEXPRESS -Q "EXEC sp_BackupDatabases @backupLocation='c:\temp_database_bak\', @backupType='F'"

FOR %%A IN (%Date%) DO (
    FOR /F "tokens=1-3 delims=/-" %%B in ("%%~A") DO (
        SET Today=%%D%%B%%C
    )
)

"C:\Program Files\7-Zip\7z.exe" a c:\backup_mssql\Database_BAK.%TODAY%.7z "C:\temp_database_bak\"

rmdir c:\temp_database_bak /S /Q

No comments:

Post a Comment

Phoenix

I am resurrecting this tech blog for notes related to Azure Logic Apps with SAP.