Skip to content

Commit 0e373a2

Browse files
committed
Merge branch 'development' into 'master'
Development See merge request sanderstad/PSDatabaseClone!4
2 parents b46de8d + 71bc38b commit 0e373a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1083
-735
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
MIT License
1+
MIT License
22

33
Copyright (c) 2018 Sander Stad
44

PSDatabaseClone.psd1

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
@{
1+
@{
22
# Script module or binary module file associated with this manifest
33
ModuleToProcess = 'PSDatabaseClone.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '1.0.0.0'
6+
ModuleVersion = '0.1.0.0'
77

88
# ID used to uniquely identify this module
99
GUID = '747980ca-0d3d-4529-b4fd-e6cdd059c62a'
1010

1111
# Author of this module
12-
Author = 'sander'
12+
Author = 'Sander Stad'
1313

1414
# Company or vendor of this module
15-
CompanyName = 'MyCompany'
15+
CompanyName = ''
1616

1717
# Copyright statement for this module
18-
Copyright = 'Copyright (c) 2018 sander'
18+
Copyright = 'Copyright (c) 2018 Sander Stad'
1919

2020
# Description of the functionality provided by this module
2121
Description = 'Cloning module for SQL Server databases'
@@ -46,32 +46,33 @@
4646
)
4747

4848
# Assemblies that must be loaded prior to importing this module
49-
# RequiredAssemblies = @()
49+
RequiredAssemblies = @("bin\PSDatabaseClone.dll")
5050

5151
# Script files (.ps1) that are run in the caller's environment prior to
5252
# importing this module
5353
# ScriptsToProcess = @()
5454

5555
# Type files (.ps1xml) to be loaded when importing this module
56-
# TypesToProcess = @('xml\PSDatabasClone.Types.ps1xml')
56+
# TypesToProcess = @('xml\PSDatabaseClone.Types.ps1xml')
5757

5858
# Format files (.ps1xml) to be loaded when importing this module
59-
# FormatsToProcess = @('xml\PSDatabasClone.Format.ps1xml')
59+
# FormatsToProcess = @('xml\PSDatabaseClone.Format.ps1xml')
6060

6161
# Modules to import as nested modules of the module specified in
6262
# ModuleToProcess
6363
# NestedModules = @()
6464

6565
# Functions to export from this module
66-
FunctionsToExport = 'Initialize-PDCVhdDisk',
67-
'Invoke-PDCRepairClone',
68-
'New-PDCClone',
69-
'New-PDCImage',
70-
'New-PDCVhdDisk',
71-
'Remove-PDCClone',
72-
'Remove-PDCImage',
73-
'Set-PDCConfiguration',
74-
'Get-PDCClone'
66+
FunctionsToExport = 'Initialize-PSDCVhdDisk',
67+
'Invoke-PSDCRepairClone',
68+
'New-PSDCClone',
69+
'New-PSDCImage',
70+
'New-PSDCVhdDisk',
71+
'Remove-PSDCClone',
72+
'Remove-PSDCImage',
73+
'Set-PSDCConfiguration',
74+
'Get-PSDCClone',
75+
'Get-PSDCImage'
7576

7677
# Cmdlets to export from this module
7778
CmdletsToExport = ''
@@ -104,12 +105,12 @@
104105
# ProjectUri = ''
105106

106107
# A URL to an icon representing this module.
107-
# IconUri = ''
108+
IconUri = 'https://www.sqlstad.nl/wp-content/uploads/2018/07/PSDatabaseClone_Logo_128.png'
108109

109110
# ReleaseNotes of this module
110111
# ReleaseNotes = ''
111112

112113
} # End of PSData hashtable
113114

114115
} # End of PrivateData hashtable
115-
}
116+
}

PSDatabaseClone.psm1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
$script:ModuleRoot = $PSScriptRoot
2-
$script:ModuleVersion = "1.0.0.0"
1+
$script:ModuleRoot = $PSScriptRoot
2+
$script:ModuleVersion = "0.1.0.0"
33

44
function Import-ModuleFile
55
{
@@ -32,8 +32,8 @@ function Import-ModuleFile
3232
}
3333

3434
# Detect whether at some level dotsourcing was enforced
35-
$script:doDotSource = Get-PSFConfigValue -FullName PSDatabasClone.Import.DoDotSource -Fallback $false
36-
if ($PSDatabasClone_dotsourcemodule) { $script:doDotSource = $true }
35+
$script:doDotSource = Get-PSFConfigValue -FullName PSDatabaseClone.Import.DoDotSource -Fallback $false
36+
if ($PSDatabaseClone_dotsourcemodule) { $script:doDotSource = $true }
3737

3838
# Execute Preimport actions
3939
. Import-ModuleFile -Path "$ModuleRoot\internal\scripts\preimport.ps1"

bin/PSDatabaseClone.dll

8.5 KB
Binary file not shown.

en-us/about_PSDatabasClone.help.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

en-us/about_PSDatabaseClone.help.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
TOPIC
2+
about_PSDatabaseClone
3+
4+
SHORT DESCRIPTION
5+
Module to create SQL Server database images and clones
6+
7+
LONG DESCRIPTION
8+
PSDatabaseClone is a PowerShell module for creating SQL Server database images and clones.
9+
It enables administrator to supply environments with database copies that are a fraction of the original size.
10+
11+
KEYWORDS
12+
PSDatabaseClone

functions/Get-PDCClone.ps1 renamed to functions/Get-PSDCClone.ps1

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
function Get-PDCClone {
1+
function Get-PSDCClone {
22
<#
33
.SYNOPSIS
4-
Get-PDCClone get on or more clones
4+
Get-PSDCClone get on or more clones
55
66
.DESCRIPTION
7-
Get-PDCClone will retrieve the clones and apply filters if needed.
7+
Get-PSDCClone will retrieve the clones and apply filters if needed.
88
By default all the clones are returned
99
1010
.PARAMETER HostName
@@ -33,17 +33,17 @@ function Get-PDCClone {
3333
https://psdatabaseclone.io/
3434
3535
.EXAMPLE
36-
Get-PDCClone -HostName host1, host2
36+
Get-PSDCClone -HostName host1, host2
3737
3838
Retrieve the clones for host1 and host2
3939
4040
.EXAMPLE
41-
Get-PDCClone -Database DB1
41+
Get-PSDCClone -Database DB1
4242
4343
Get all the clones that have the name DB1
4444
4545
.EXAMPLE
46-
Get-PDCClone -ImageName DB1_20180703085917
46+
Get-PSDCClone -ImageName DB1_20180703085917
4747
4848
Get all the clones that were made with image "DB1_20180703085917"
4949
#>
@@ -62,7 +62,7 @@ function Get-PDCClone {
6262

6363
# Test the module database setup
6464
try {
65-
Test-PDCConfiguration -EnableException
65+
Test-PSDCConfiguration -EnableException
6666
}
6767
catch {
6868
Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue
@@ -97,6 +97,7 @@ function Get-PDCClone {
9797
"
9898

9999
try {
100+
$results = @()
100101
$results = Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -Database $pdcDatabase -Query $query -As PSObject
101102
}
102103
catch {
@@ -128,7 +129,24 @@ function Get-PDCClone {
128129
$results = $results | Where-Object {$_.ImageLocation -in $ImageLocation}
129130
}
130131

131-
return $results
132+
# Convert the results to the PSDCClone data type
133+
foreach($result in $results){
134+
135+
[PSDCClone]$clone = New-Object PSDCClone
136+
$clone.CloneID = $result.CloneID
137+
$clone.CloneLocation = $result.CloneLocation
138+
$clone.AccessPath = $result.AccessPath
139+
$clone.SqlInstance = $result.SqlInstance
140+
$clone.DatabaseName = $result.DatabaseName
141+
$clone.IsEnabled = $result.IsEnabled
142+
$clone.ImageID = $result.ImageID
143+
$clone.ImageName = $result.ImageName
144+
$clone.ImageLocation = $result.ImageLocation
145+
$clone.HostName = $result.HostName
146+
147+
return $clone
148+
}
149+
132150
}
133151

134152
end {
@@ -140,4 +158,4 @@ function Get-PDCClone {
140158

141159
}
142160

143-
}
161+
}

functions/Get-PSDCImage.ps1

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
function Get-PSDCImage {
2+
<#
3+
.SYNOPSIS
4+
Get-PSDCImage get on or more clones
5+
6+
.DESCRIPTION
7+
Get-PSDCImage will retrieve the clones and apply filters if needed.
8+
By default all the clones are returned
9+
10+
.PARAMETER ImageID
11+
Filter based on the image id
12+
13+
.PARAMETER ImageName
14+
Filter based on the image name
15+
16+
.PARAMETER ImageLocation
17+
Filter based on the image location
18+
19+
.PARAMETER Database
20+
Filter based on the database
21+
22+
.NOTES
23+
Author: Sander Stad (@sqlstad, sqlstad.nl)
24+
25+
Website: https://psdatabaseclone.io
26+
Copyright: (C) Sander Stad, [email protected]
27+
License: MIT https://opensource.org/licenses/MIT
28+
29+
.LINK
30+
https://psdatabaseclone.io/
31+
32+
.EXAMPLE
33+
Get-PSDCImage -ImageName DB1_20180704220944, DB2_20180704221144
34+
35+
Retrieve the images for DB1_20180704220944, DB2_20180704221144
36+
37+
.EXAMPLE
38+
Get-PSDCImage -ImageLocation "\\fileserver1\psdatabaseclone\images\DB1_20180704220944.vhdx"
39+
40+
Get all the images that are the same as the image location
41+
42+
.EXAMPLE
43+
Get-PSDCImage -Database DB1, DB2
44+
45+
Get all the images that were made for databases DB1 and DB2
46+
#>
47+
48+
[CmdLetBinding()]
49+
50+
param(
51+
[int[]]$ImageID,
52+
[string[]]$ImageName,
53+
[string[]]$ImageLocation,
54+
[string[]]$Database
55+
)
56+
57+
begin {
58+
# Test the module database setup
59+
try {
60+
Test-PSDCConfiguration -EnableException
61+
}
62+
catch {
63+
Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue
64+
}
65+
66+
$pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.server
67+
$pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name
68+
}
69+
70+
process {
71+
# Test if there are any errors
72+
if (Test-PSFFunctionInterrupt) { return }
73+
74+
$query = "
75+
SELECT ImageID,
76+
ImageName,
77+
ImageLocation,
78+
SizeMB,
79+
DatabaseName,
80+
DatabaseTimestamp,
81+
CreatedOn
82+
FROM dbo.Image;
83+
"
84+
85+
try {
86+
$result = @()
87+
$results = Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -Database $pdcDatabase -Query $query -As PSObject
88+
}
89+
catch {
90+
Stop-PSFFunction -Message "Could not execute query" -ErrorRecord $_ -Target $query
91+
}
92+
93+
# Filter image id
94+
if ($ImageID) {
95+
$results = $results | Where-Object {$_.ImageID -in $ImageID}
96+
}
97+
98+
# Filter image name
99+
if ($ImageName) {
100+
$results = $results | Where-Object {$_.ImageName -in $ImageName}
101+
}
102+
103+
# Filter image location
104+
if ($ImageLocation) {
105+
$results = $results | Where-Object {$_.ImageLocation -in $ImageLocation}
106+
}
107+
108+
# Filter database
109+
if ($Database) {
110+
$results = $results | Where-Object {$_.DatabaseName -in $Database}
111+
}
112+
113+
114+
# Convert the results to the PSDCClone data type
115+
foreach($result in $results){
116+
117+
[PSDCImage]$image = New-Object PSDCImage
118+
$image.ImageID = $result.ImageID
119+
$image.ImageName = $result.ImageName
120+
$image.ImageLocation = $result.ImageLocation
121+
$image.SizeMB = $result.SizeMB
122+
$image.DatabaseName = $result.DatabaseName
123+
$image.DatabaseTimestamp = $result.DatabaseTimestamp
124+
$image.CreatedOn = $result.CreatedOn
125+
126+
return $image
127+
}
128+
}
129+
130+
end {
131+
# Test if there are any errors
132+
if (Test-PSFFunctionInterrupt) { return }
133+
134+
Write-PSFMessage -Message "Finished retrieving image(s)" -Level Verbose
135+
}
136+
}

0 commit comments

Comments
 (0)