Skip to content

Instantly share code, notes, and snippets.

@isummation
Last active July 12, 2019 06:42
Show Gist options
  • Save isummation/2aa74e0ee0e4ab195c4804bbae9e127a to your computer and use it in GitHub Desktop.
Save isummation/2aa74e0ee0e4ab195c4804bbae9e127a to your computer and use it in GitHub Desktop.
Create script to take backup for all database
SELECT
'BACKUP DATABASE [' + name + '] TO DISK = ''C:\sqlbackup\' + name + '.bak'''
FROM sys.databases ;
SELECT
'RESTORE DATABASE [' + name + '] FROM DISK = ''/var/opt/mssql/data/' + name + '.bak'' WITH MOVE ''' + name + ''' to ''/var/opt/mssql/data/' + name + '.mdf'', MOVE ''' + name + '_log'' to ''/var/opt/mssql/data/' + name + '.ldf'''
FROM sys.databases ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment