Last active
April 12, 2018 09:52
-
-
Save juanonsoftware/44fd8ce4211643f8c5132ac7b985be59 to your computer and use it in GitHub Desktop.
Script to backup an SQL Server database
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
-- NOTE | |
-- Must update dbName & Folder | |
declare @dbName nvarchar(150); | |
declare @folder nvarchar(100); | |
set @dbName = 'TestDB'; | |
set @folder = 'D:\Mega\Wip\SQL\TestDB\Backup\'; | |
declare @path nvarchar(255); | |
declare @dateInfo nvarchar(50); | |
-- https://msdn.microsoft.com/en-us/library/ms186862.aspx | |
set @dateInfo = REPLACE(convert(nvarchar, getdate(), 20), ':', ''); | |
set @dateInfo = REPLACE(@dateInfo, '-', ''); | |
set @dateInfo = REPLACE(@dateInfo, ' ', '-'); | |
set @path = @folder + @dbName + '-' + @dateInfo + '.bak'; | |
print 'Backup path: ' + @path; | |
-- https://msdn.microsoft.com/en-us/library/ms187510.aspx | |
backup database @dbName | |
to disk = @path | |
WITH | |
DIFFERENTIAL | |
--COMPRESSION | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment