Created
March 7, 2014 16:31
-
-
Save andrewthauer/9414764 to your computer and use it in GitHub Desktop.
Backup an MS SQL database using using a timestamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @dbName nvarchar(max) = '<db_name>' | |
DECLARE @path nvarchar(max) = '<destination_path>' | |
DECLARE @date datetime = GETDATE() | |
DECLARE @timeStamp nvarchar(max) = CONVERT(nvarchar(max), @date, 112) + '-' + REPLACE(CONVERT(nvarchar(max), @date, 108), ':', '') | |
DECLARE @fileName nvarchar(max) = @path + @dbName + '_' + @timeStamp + '.bak' | |
BACKUP DATABASE @dbName TO DISK = @fileName | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment