These pages cover SQL Clone Technical Preview 0.2 to 0.3, which is not the latest version. Help for other versions is also available.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

The installer automatically sets up PowerShell to use the InstantClone PowerShell module (located at: C:\Program Files (x86)\Red Gate\Instant Clone X.Y.Z\Redgate.InstantClone.PowerShell) Run the PowerShell command-line or ISE as an administrator. Use the cmdlets like this. Finish all invocations with –Verbose to see debug output. 

# Set connection string for use by Instant Clone. Only need to do this the first time

 Save-InstantCloneOptions -SourceConnectionString "Server=JOHNSMITHTEST\sql2012;Trusted_Connection=True" -TargetConnectionString "Server=JOHNSMITHTEST\sql2012;Trusted_Connection=True" -Verbose 
 

# Save a snapshot of my WidgetProd database to disk 

Save-InstantCloneSnapshot -DatabaseName WidgetProd -SnapshotName WidgetSnp1 -Verbose

# Create a couple of clones from the WidgetSnp1 snapshot
New-InstantCloneClone -NewDatabaseName WidgetClone1 -SnapshotName WidgetSnp1 -Verbose
New-InstantCloneClone -NewDatabaseName WidgetClone2 -SnapshotName WidgetSnp1 -Verbose

# I'm bored with these clones now. Let's drop them
Remove-InstantCloneClone -CloneName WidgetClone1 -Verbose
Remove-InstantCloneClone -CloneName WidgetClone2 -Verbose

# Let's drop that snapshot too
Remove-InstantCloneSnapshot -SnapshotName WidgetSnp1 -Verbose

 

When you restart your machine, clone databases will be offline until you run the restore cmdlet:
Restore-InstantClone -Verbose

See all the clones and snapshots with the Show-InstantCloneSnapshots/Clones cmdlets
Show-InstantCloneSnapshots -Verbose
Show-InstantCloneClones -Verbose

See all cmdlets available with the Get-Command cmdlet:
Get-Command -Module RedGate.InstantClone.PowerShell

Setting storage locations

Snapshots and clones are stored by default in C:\Users\YourUser\Documents\Red Gate Instant Clone. If you want to change this, use the Save-InstantCloneOptions cmdlet:

Save-InstantCloneOptions -SnapshotFolder D:\IC\Snapshots -Verbose
Save-InstantCloneOptions -CloneFolder D:\IC\Clones -Verbose

Working as a team with the PowerShell cmdlets

You may want to create a snapshot on one machine and use it on another. For instance, your colleagues might want to use your snapshots, or you might want to create a snapshot on one SQL Server and clone it on another.

Snapshots are, by default, local. Their metadata is stored locally, and they are only cloneable on your machine. You can create a Shared Snapshot which is stored in your Shared Snapshot Folder. This snapshot and can be used on any machine.

To use shared snapshots, each computer should have it's SharedSnapshotsFolder set to a common location e.g. \\john-pc\sharedsnapshots. When you take a snapshot, use the -PutInSharedFolder parameter. The snapshots will then be created in \\john-pc\sharedsnapshots. Then, on any machine, simply create a clone with that name.

Creating a shared snapshot using the PowerShell cmdlets

On machine 1:

Save-InstantCloneOptions -SharedSnapshotFolder \\john-pc\SharedSnapshots  -Verbose

Save-InstantCloneSnapshot -DatabaseName AdventureWorks2012 -SnapshotName aworks_shared -Verbose  -PutInSharedFolder

On machine 2:

Save-InstantCloneOptions -SharedSnapshotFolder \\john-pc\SharedSnapshots

New-InstantCloneClone -NewDatabaseName awc1_shared -SnapshotName aworks_shared -Verbose

Sharing an existing snapshot using the PowerShell cmdlets

You may want to create a snapshot on one machine, but clone it on another. To do this:

  • On the source machineSetup your shared folder with the Save-InstantCloneOptions cmdlet:

Save-InstantCloneOptions -SharedSnapshotFolder [\\myServer\SharedSnapshots|\\myServer\SharedSnapshots] -Verbose 

  • Create a snapshot as usual with the Save-InstantCloneSnapshot cmdlet:

Save-InstantCloneSnapshot -DatabaseName AdventureWorks -SnapshotName AdvSnap -Verbose

  • Run the Save-InstantCloneSharedSnapshot cmdlet. This will copy your Snapshot into the shared-directory so it can be accessed by others.

Save-InstantCloneSharedSnapshot -SnapshotName AdvSnap -NewSnapshotName AdvSnapShared

To delete a shared-snapshot, delete the relevant GUID-named directory.


On the target machine:

  • Setup your shared folder with the Save-InstantCloneOptions cmdlet:

Save-InstantCloneOptions -SharedSnapshotFolder [\\myServer\SharedSnapshots|\\myServer\SharedSnapshots] -Verbose

  • (Optional) Run Show-InstantCloneSnapshot cmdlet. AdvSnapShared is listed.

Show-InstantCloneSnapshots -Verbose

  • Run the New-InstantCloneClone cmdlet to create a new clone from the shared-snapshot.

New-InstantCloneClone -SnapshotName AdvSnapShared -NewDatabaseName AdvClone -Verbose 

  • No labels