Creating a differential backup
This recipe shows how you can create a differential backup on your database.
Getting ready
We will use the AdventureWorks2008R2
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 similar to:
BACKUP DATABASE [AdventureWorks2008R2] TO DISK = N'C:\Backup\AdventureWorks2008R2_Diff_20120227092409.bak' WITH DIFFERENTIAL , NOFORMAT, INIT, NAME = N'AdventureWorks2008R2 Diff Backup', NOSKIP, REWIND, NOUNLOAD, COMPRESSION, STATS = 10, CHECKSUM
How to do it...
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking
Add the following script and run:
$instanceName = "KERRIGAN" $server = New-Object...