Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a differential backup


This recipe will discuss how you can create a differential backup on your database.

Getting ready

We will use the AdventureWorks2014 database for this recipe. We will create a differential 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 like this:

BACKUP DATABASE [AdventureWorks2014]
TO  DISK = N'C:\Backup\AdventureWorks2014_Diff_20150314092409.bak'
WITH  DIFFERENTIAL , NOFORMAT, INIT,
NAME = N'AdventureWorks2014 Diff Backup',
NOSKIP, REWIND, NOUNLOAD, COMPRESSION,
STATS = 10, CHECKSUM

How to do it...

Let's list the steps required to create a differential database backup:

  1. Open PowerShell ISE as administrator.

  2. Import the SQLPS module as follows:

    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking
  3. Add the following script and run:

    $instanceName = "localhost"
    $server = New-Object -TypeName...