Created
April 11, 2018 18:35
-
-
Save brazilnut2000/ea676998144067540033914e6e1ba9a2 to your computer and use it in GitHub Desktop.
Backup SQL Server Database with Powershell
This file contains 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
# Install SQL Server PowerShell module | |
# https://docs.microsoft.com/en-us/sql/powershell/download-sql-server-ps-module | |
Install-Module -Name SqlServer | |
# Backing Up SQL Server Databases is Easier in PowerShell than T-SQL | |
# http://www.sqlservercentral.com/articles/PowerShell/151510/ | |
Get-SqlDatabase -ServerInstance [SERVERNAME]\SQLEXPRESS | | |
Where { $_.Name -eq '[DATABASENAME]' } | | |
Backup-SqlDatabase -BackupFile "c:\temp\[FILE PREFIX]$(Get-Date -UFormat %Y%m%d_%H%M).bak" -Script | |
# Remove -Script to actually execute the backup, keep it to see the command that will be generated |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment