O'Reilly logo

SQL Server 2012 with PowerShell V3 Cookbook by Donabel Santos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a full backup

In this recipe, we will look at how we can do a full database backup using PowerShell.

Getting ready

We will use the AdventureWorks2008R2 database for this recipe. We will create a full compressed backup of the database to a timestamped .bak file in the C:\Backup folder. Feel free to use a database of your choice for this task.

The T-SQL syntax that will be generated by this PowerShell recipe will look similar to:

BACKUP DATABASE [AdventureWorks2008R2] 
TO  DISK = N'C:\Backup\AdventureWorks2008R2_Full_20120227092409.bak'
WITH NOFORMAT, INIT,  
NAME = N'AdventureWorks2008R2 Full Backup', 
NOSKIP, REWIND, NOUNLOAD, COMPRESSION,  
STATS = 10, CHECKSUM

How to do it...

  1. Open the PowerShell console by going to Start | Accessories | Windows ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required