Created
March 22, 2016 22:58
-
-
Save brazilnut2000/2896938fcd07c1cccc55 to your computer and use it in GitHub Desktop.
Back up a SQL Server database, regardless of version (certain versions don't support scheduled backups via SSMS)
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
$instanceName = "[db instance name goes here]" | |
$server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName | |
$databasename = "[db name goes here]" | |
$timestamp = Get-Date -Format yyyyMMddHHmmss | |
$backupfolder = "[full path to backup folder]" | |
$backupfile = "$($databasename)_Full_$($timestamp).bak" | |
$fullBackupFile = Join-Path $backupfolder $backupfile | |
Backup-SqlDatabase ` | |
-ServerInstance $instanceName ` | |
-Database $databasename ` | |
-BackupFile $fullBackupFile ` | |
-Checksum ` | |
-Initialize ` | |
-BackupSetName "$databasename Full Backup" ` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment