forked from Sitecore/Sitecore.Demo.Retail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup-demo-data.ps1
72 lines (51 loc) · 3.12 KB
/
backup-demo-data.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Set-ExecutionPolicy Unrestricted –scope CurrentUser
Import-Module CSPS -Force
Import-Module $PSScriptRoot\Scripts\Commerce\ManageFile.psm1 -Force
Import-Module $PSScriptRoot\Scripts\Commerce\ManageIIS.psm1 -Force
Import-Module $PSScriptRoot\Scripts\Commerce\ManageUser.psm1 -Force
Import-Module $PSScriptRoot\Scripts\Commerce\ManageRegistry.psm1 -Force
Import-Module $PSScriptRoot\Scripts\Commerce\ManageSqlServer.psm1 -Force
Import-Module $PSScriptRoot\Scripts\Demo\ManageDemoData.psm1 -Force
cd $PSScriptRoot
If ((ManageUser\Confirm-Admin) -ne $true) { Write-Host "Please run script as administrator"; exit }
If ((ManageRegistry\Get-InternetExplorerEnhancedSecurityEnabled -Verbose) -eq $true) { Write-Host "Please disable Internet Explorer Enhanced Security"; exit }
$settings = ((Get-Content $PSScriptRoot\install-commerce-config.json -Raw) | ConvertFrom-Json)
$sitecoreWebsiteFolderSetting = ($settings.iis.websites | Where { $_.id -eq "sitecore" } | Select)
If ($sitecoreWebsiteFolderSetting -eq $null) { Write-Host "Expected sitecore iis website settings" -ForegroundColor red; exit; }
$siteName = $sitecoreWebsiteFolderSetting.siteName
$sitecoreApplicationPoolSetting = ($settings.iis.appPools)
$backupRootPath = "C:\websites\habitat.dev.local\Databases\Backup"
$mongoBackupDataPath = "$backupRootPath\MongoData"
$sqlDbPath = "c:\websites\$siteName\databases"
$sqlDbBackupPath = "$backupRootPath\SQL"
$mongoBinDirectory = "C:\MongoDB\Server\bin"
#Step : Empty output directory
Write-Host "`nCleaning Backup Directory $backupRootPath" -foregroundcolor Yellow
If((ManageFile\Clean-Directory -path $backupRootPath -Verbose) -ne 0) {Exit }
ManageFile\Create-Directory -path $mongoBackupDataPath
ManageFile\Create-Directory -path $sqlDbBackupPath
# Step : Stop sites
Write-Host "`nStopping Application Pools" -foregroundcolor Yellow
Foreach ($appPool in $settings.iis.appPools)
{
ManageIIS\Stop-ApplicationPool -appPoolName $appPool.name -Verbose
}
# Step : Export Mongo Data
Write-Host "`nExporting Mongo Data" -foregroundcolor Yellow
ManageDemoData\Export-MongoData -mongoBinDirectory $mongoBinDirectory -outputDirectory $mongoBackupDataPath
Write-Host "`nDetaching SQL databases" -foregroundcolor Yellow
# Step : Detach SQL Databases
ManageSqlServer\Detach-Databases -prefix "demo.local" -ServerName "(local)" -Verbose
ManageSqlServer\Detach-Databases -prefix "habitat821" -ServerName "(local)" -Verbose
# Step : Copy data files to backup directory
Write-Host "`nCopying SQL Data files from $sqlDbPath to backup directory: $sqlDbBackupPath" -foregroundcolor Yellow
ManageFile\Copy-SQLDataFiles -prefix "demo.local" -sourcePath $sqlDbPath -destinationPath $sqlDbBackupPath -Verbose
ManageFile\Copy-SQLDataFiles -prefix "habitat821" -sourcePath $sqlDbPath -destinationPath $sqlDbBackupPath -Verbose
Write-Host "`nRe-Attaching databases" -foregroundcolor Yellow
ManageSqlServer\Attach-Databases -DbPath $sqlDbPath -prefix "" -ServerName "(local)" -Verbose
# Step : Start sites
Write-Host "`nStarting Application Pools" -foregroundcolor Yellow
Foreach ($appPool in $settings.iis.appPools)
{
ManageIIS\Start-ApplicationPool -appPoolName $appPool.name -Verbose
}