Skip to content

Instantly share code, notes, and snippets.

@vaneves
Last active August 29, 2015 14:21
Show Gist options
  • Save vaneves/e5f7fe87dca525d9db52 to your computer and use it in GitHub Desktop.
Save vaneves/e5f7fe87dca525d9db52 to your computer and use it in GitHub Desktop.
Backup SQL Server
DECLARE @FileName AS VARCHAR(30), @FullPath AS VARCHAR(200), @Database sysname;
SET @Database = 'MyDatabaseName';
SET @FileName = CONVERT(VARCHAR(30), GETDATE(), 20);
SET @FileName = REPLACE(@FileName, '-', '');
SET @FileName = REPLACE(@FileName, ' ', '');
SET @FileName = REPLACE(@FileName, ':', '');
SET @FileName = @Database + '_' + @FileName + '.bak';
SET @FullPath = 'C:\MyBackups\Path\' + @FileName;
BACKUP DATABASE @Database TO DISK = @FullPath;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment