Image compaction

This feature requires SQL Clone 4.4 and Windows 8 / Server 2012 or later.

Image compaction takes time

Please be aware that even for small images, image compaction can take some time to complete and it will slow down your image creation process. The amount of time depends mostly on your available CPU cycle and the speed of your disk subsystem.


Image compaction reduces the size of an image that is being created. This is useful if you have run modifications that have reduced the size of your database as the image will be reduced to match.

Image compaction will be run at the very end of the image creation process, so there must be sufficient disk space available to house the uncompacted image temporarily. For example, if you are imaging a 40 GB database, and dropping 30 GB of data from it to create a final 10 GB image, you will still need 40 GB of disk space available to store the image until it is compacted down.

PowerShell

Pass the CompactImage parameter with a value of Compact to the New-SqlCloneImage cmdlet.

$truncateAndShrinkScript = New-SqlCloneSqlScript -Path \\data-scripts\truncate_shrink.sql
 
$ImageOperation = New-SqlCloneImage -Name "AdventureWorks" `
    -SqlServerInstance <YourSqlServerInstance> `
    -BackupFileName @('\\red-gate\backups\AdventureWorks.bak') `
    -Destination <YourImageDestination>`
    -Modifications $truncateAndShrinkScript `
    -CompactImage Compact
 
$ImageOperation | Wait-SqlCloneOperation

Example modifications

Truncate data and shrink database

In this example we truncate a large table within our database that we don't need for development purposes. By removing the rows in the table and then shrinking the database we remove this data from the underlying database files. This will reclaim the free space and produce an image of the same size as if this data did not exist in the original database.

TRUNCATE TABLE [dbo].[LotsOfRows];
GO

DBCC SHRINK DATABASE (0, 10);
GO




Didn't find what you were looking for?