Skip to content

Basic Powershell SQL Backup – 2012

#run sqlps.exe to automatically load the sqlps module
#e.g. sqlps bu_AdHoc.ps1 -db Testing -Server DemoServer -Dest C:\Backups

param([string]$db ,[string]$Server, [string]$dest);

$timestamp = Get-Date -format yyyy_MM_dd_HHmmss;
$Dest = $Dest + “\” + $db + “_full_” + $timestamp + “.bak”, “File”;
$BackupSetName = “Full backup of ” + $db + ” ” + $timestamp;

Backup-SqlDatabase -ServerInstance $Server -Database $db -BackupFile $Dest -CopyOnly -Initialize -Checksum -CompressionOption On -BackupSetName $BackupSetName

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s