Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@brazilnut2000
Created March 22, 2016 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brazilnut2000/2896938fcd07c1cccc55 to your computer and use it in GitHub Desktop.
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)
$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