Skip to content

Commit 5410e29

Browse files
committed
Merge branch 'development' into 'master'
Development to Master See merge request sanderstad/PSDatabaseClone!2
2 parents ad0ef9b + a8d447e commit 5410e29

14 files changed

Lines changed: 623 additions & 282 deletions

PSDatabasClone.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
'New-PdcVhdDisk',
7171
'Remove-PdcDatabaseClone',
7272
'Remove-PdcDatabaseImage',
73-
'Set-PdcConfiguration'
73+
'Set-PdcConfiguration'
7474

7575
# Cmdlets to export from this module
7676
CmdletsToExport = ''

functions/Initialize-PdcVhdDisk.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ function Initialize-PdcVhdDisk {
1818
.NOTES
1919
Author: Sander Stad (@sqlstad, sqlstad.nl)
2020
21-
Website: https://easyclone.io
21+
Website: https://psdatabaseclone.io
2222
Copyright: (C) Sander Stad, sander@sqlstad.nl
2323
License: MIT https://opensource.org/licenses/MIT
2424
2525
.LINK
26-
https://easyclone.io/
26+
https://psdatabaseclone.io/
2727
2828
.EXAMPLE
2929
Initialize-PdcVhdDisk -Path $path
@@ -41,7 +41,7 @@ function Initialize-PdcVhdDisk {
4141

4242
Param(
4343
[Parameter(Mandatory = $true)]
44-
[string[]]$Path,
44+
[string]$Path,
4545
[System.Management.Automation.PSCredential]
4646
$Credential,
4747
[ValidateSet('GPT', 'MBR')]
@@ -95,7 +95,7 @@ function Initialize-PdcVhdDisk {
9595

9696
# Create the partition, set the drive letter and format the volume
9797
try {
98-
$volume = Get-Disk -Number $disk.DiskNumber | New-Partition -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "EasyClone" -AllocationUnitSize $AllocationUnitSize -Confirm:$false
98+
$volume = Get-Disk -Number $disk.DiskNumber | New-Partition -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "PSDatabaseClone" -AllocationUnitSize $AllocationUnitSize -Confirm:$false
9999
}
100100
catch {
101101
# Dismount the drive

functions/Invoke-PdcCloneSetup.ps1

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

functions/Invoke-PdcRepairClone.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function Invoke-PdcRepairClone {
2-
<#
2+
<#
33
.SYNOPSIS
44
Invoke-PdcRepairClone repairs the clones
55
@@ -24,12 +24,12 @@ function Invoke-PdcRepairClone {
2424
.NOTES
2525
Author: Sander Stad (@sqlstad, sqlstad.nl)
2626
27-
Website: https://easyclone.io
27+
Website: https://psdatabaseclone.io
2828
Copyright: (C) Sander Stad, sander@sqlstad.nl
2929
License: MIT https://opensource.org/licenses/MIT
3030
3131
.LINK
32-
https://easyclone.io/
32+
https://psdatabaseclone.io/
3333
3434
.EXAMPLE
3535
Invoke-PdcRepairClone -Hostname Host1
@@ -48,12 +48,13 @@ function Invoke-PdcRepairClone {
4848
)
4949

5050
begin {
51-
# Get the configurations for the program database
52-
$ecDatabaseName = Get-PSFConfigValue -FullName psdatabaseclone.database.name
53-
$ecDatabaseServer = Get-PSFConfigValue -FullName psdatabaseclone.database.Server
54-
5551
# Test the module database setup
56-
Test-PdcDatabaseSetup -SqlInstance $ecDatabaseServer -SqlCredential $SqlCredential -Database $ecDatabaseName
52+
$result = Test-PdcConfiguration
53+
54+
if(-not $result.Check){
55+
Stop-PSFFunction -Message $result.Message -Target $result -Continue
56+
return
57+
}
5758

5859
}
5960

@@ -78,6 +79,8 @@ function Invoke-PdcRepairClone {
7879
WHERE h.HostName = '$hst';
7980
"
8081

82+
Write-PSFMessage -Message "Query Host Clones`n$query" -Level Debug
83+
8184
# Get the clones registered for the host
8285
try {
8386
Write-PSFMessage -Message "Get the clones for host $hst" -Level Verbose

functions/New-PdcDatabaseClone.ps1

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function New-PdcDatabaseClone {
2-
<#
2+
<#
33
.SYNOPSIS
44
New-PdcDatabaseClone creates a new clone
55
@@ -40,12 +40,12 @@ function New-PdcDatabaseClone {
4040
.NOTES
4141
Author: Sander Stad (@sqlstad, sqlstad.nl)
4242
43-
Website: https://easyclone.io
43+
Website: https://psdatabaseclone.io
4444
Copyright: (C) Sander Stad, sander@sqlstad.nl
4545
License: MIT https://opensource.org/licenses/MIT
4646
4747
.LINK
48-
https://easyclone.io/
48+
https://psdatabaseclone.io/
4949
5050
.EXAMPLE
5151
New-PdcDatabaseClone -SqlInstance SQLDB1 -ParentVhd C:\Temp\images\DB1_20180623203204.vhdx -Destination C:\Temp\clones\ -CloneName DB1_Clone1
@@ -94,12 +94,13 @@ function New-PdcDatabaseClone {
9494

9595
Write-PSFMessage -Message "Started image creation" -Level Output
9696

97-
# Get the configurations for the program database
98-
$ecDatabaseName = Get-PSFConfigValue -FullName psdatabaseclone.database.name
99-
$ecDatabaseServer = Get-PSFConfigValue -FullName psdatabaseclone.database.Server
100-
10197
# Test the module database setup
102-
Test-PdcDatabaseSetup -SqlInstance $ecDatabaseServer -SqlCredential $SqlCredential -Database $ecDatabaseName
98+
$result = Test-PdcConfiguration
99+
100+
if(-not $result.Check){
101+
Stop-PSFFunction -Message $result.Message -Target $result -Continue
102+
return
103+
}
103104

104105
# Random string
105106
$random = -join ((65..90) + (97..122) | Get-Random -Count 5 | ForEach-Object {[char]$_})
@@ -156,7 +157,7 @@ function New-PdcDatabaseClone {
156157
[DatabaseName],
157158
[DatabaseTimestamp],
158159
[CreatedOn]
159-
FROM [EasyClone].[dbo].[Image]
160+
FROM [dbo].[Image]
160161
WHERE DatabaseName = '$db'
161162
ORDER BY CreatedOn DESC;
162163
"
@@ -322,6 +323,8 @@ function New-PdcDatabaseClone {
322323
SELECT @HostID AS HostID
323324
"
324325

326+
Write-PSFMessage -Message "Query New Host`n$query" -Level Debug
327+
325328
$hostId = (Invoke-DbaSqlQuery -SqlInstance $ecDatabaseServer -Database $ecDatabaseName -Query $query).HostID
326329
}
327330
else {
@@ -355,6 +358,8 @@ function New-PdcDatabaseClone {
355358
@IsEnabled = $active -- bit
356359
"
357360

361+
Write-PSFMessage -Message "Query New Clone`n$query" -Level Debug
362+
358363
# execute the query
359364
$null = Invoke-DbaSqlQuery -SqlInstance $ecDatabaseServer -Database $ecDatabaseName -Query $query
360365
}

functions/New-PdcDatabaseImage.ps1

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function New-PdcDatabaseImage {
2-
<#
2+
<#
33
.SYNOPSIS
44
New-PdcDatabaseImage creates a new image
55
@@ -60,12 +60,12 @@ function New-PdcDatabaseImage {
6060
.NOTES
6161
Author: Sander Stad (@sqlstad, sqlstad.nl)
6262
63-
Website: https://easyclone.io
63+
Website: https://psdatabaseclone.io
6464
Copyright: (C) Sander Stad, sander@sqlstad.nl
6565
License: MIT https://opensource.org/licenses/MIT
6666
6767
.LINK
68-
https://easyclone.io/
68+
https://psdatabaseclone.io/
6969
7070
.EXAMPLE
7171
New-PdcDatabaseImage -SourceSqlInstance SQLDB1 -DestinationSqlInstance SQLDB2 -ImageLocalPath C:\Temp\images\ -Database DB1 -CreateFullBackup
@@ -118,19 +118,18 @@ function New-PdcDatabaseImage {
118118

119119
begin {
120120

121-
# Get the configurations for the program database
122-
$ecDatabaseName = Get-PSFConfigValue -FullName psdatabaseclone.database.name -Fallback "NotConfigured"
123-
$ecDatabaseServer = Get-PSFConfigValue -FullName psdatabaseclone.database.Server -Fallback "NotConfigured"
124-
125121
# Test the module database setup
126-
try{
127-
Test-PdcDatabaseSetup -SqlInstance $ecDatabaseServer -SqlCredential $SqlCredential -Database $ecDatabaseName
128-
}
129-
catch{
130-
Stop-PSFFunction -Message "Something went wrong testing the module configuration" -ErrorRecord $_ -Target $SourceSqlInstance
122+
$result = Test-PdcConfiguration
123+
124+
if(-not $result.Check){
125+
Stop-PSFFunction -Message $result.Message -Target $result -Continue
131126
return
132127
}
133128

129+
$pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.Server
130+
$pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name
131+
132+
134133
Write-PSFMessage -Message "Started image creation" -Level Output
135134

136135
# Try connecting to the instance
@@ -265,7 +264,7 @@ function New-PdcDatabaseImage {
265264
try {
266265
Write-PSFMessage -Message "Initializing the vhd $imageName.vhd" -Level Verbose
267266

268-
$diskResult = Initialize-PdcVhdDisk -Path $vhdDisk.Path -Credential $DestinationCredential
267+
$diskResult = Initialize-PdcVhdDisk -Path $vhdPath -Credential $DestinationCredential
269268
}
270269
catch {
271270
Stop-PSFFunction -Message "Couldn't initialize vhd $vhdPath" -Target $imageName -ErrorRecord $_ -Continue
@@ -321,7 +320,7 @@ function New-PdcDatabaseImage {
321320
}
322321

323322
# Setup the temporary database name
324-
$tempDbName = "$($db.Name)-EasyClone"
323+
$tempDbName = "$($db.Name)-PSDatabaseClone"
325324

326325
# Restore database to image folder
327326
try {
@@ -375,9 +374,11 @@ function New-PdcDatabaseImage {
375374
@DatabaseTimestamp = '$databaseTS' -- datetime
376375
"
377376

377+
Write-PSFMessage -Message "Query New Image`n$query" -Level Debug
378+
378379
Write-PSFMessage -Message "Saving image information in database" -Level Verbose
379380

380-
Invoke-DbaSqlQuery -SqlInstance $ecDatabaseServer -Database $ecDatabaseName -Query $query
381+
Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -Database $pdcDatabase -Query $query
381382

382383
}
383384
catch {

0 commit comments

Comments
 (0)