Applicable products

√ Cortex Project History 1.x

√ Cortex 365


Prerequisites

  • Administrative rights on the Cortex host server


Assumptions

  • IIS, SQL and MongoDB are all on the same (single) server.


Overview

The following script includes a section at the top to edit.

Edit the values in the following lines (as required):

  • 6
  • 9
  • 12 - 15
  • 18
  • 20
  • 23
  • 24
  • 28
  • 30

Save as a .ps1 (PowerShell script) and execute.


####################################################
########  Edit the following information  ##########
####################################################

# Enter the path to the backup Root folder.
$backupRoot = 'F:\Backup_Root'

# Enter the name of the Eos Cortex Website, as listed in IIS Manager.
$siteName = 'EosCortexCLI01'
# Enter the path to inetpub\wwwroot if the path was changed at install
# Otherwise, leave these paths as-is.
$appAuthFile =   "C:\inetpub\wwwroot\" + $siteName + "\ph\auth.config"
$siteConfigFile = "C:\inetpub\wwwroot\" + $siteName + "\Web.config"
$appConfigFile = "C:\inetpub\wwwroot\" + $siteName + "\ph\Web.config"
$AppLogoFile =   "C:\inetpub\wwwroot\" + $siteName + "\ph\Content\css\img\Cortex-app-logo.png"

# Enter the SQL Server Instance (Server name \ Instance name).
$sqlInstance = "ServerName\SQLInstance"
# Enter the Eos Cortex SQL Database name.
$sqlDbName = "EosCortexCLI01"

# Enter the path to the 'bin' folder for MongoDB.
$mongoDir = 'C:\Program Files\MongoDB\Server\3.6\bin'
# Enter the MongoDB name.
$mongoDbName = 'EosCortexCLI01'
$mongoAuthEnabled = 1
# Enter the MongoDB username.
$mongoUsr = 'EosCortexCLI01'
# Enter the MongoDB user password.
$mongoPwd = 'SomeVeryComplexPassword'
$mongoDBPort = '27017'

####################################################
############## Customization End ###################
####################################################

###### Stop the IIS (Website) #####
Import-Module WebAdministration
Stop-WebSite $siteName

###### Set the backup location #####
$backupPath = $backupRoot + '\bkp_' + (Get-Date -Format "yyyyMMdd").ToString()
    New-Item -ItemType directory -Force -Path $backupPath

###### Backup the IIS config files #####
$appAuthFileBackup = $backupPath + '\' + $siteName + '-' + (Get-Date -Format "yyyyMMdd").ToString() + '-app-auth.config'
    "Backing up app-auth.config to :: " + $appAuthFileBackup
    Copy-Item $appAuthFile -Destination $appAuthFileBackup

$appConfigFileBackup = $backupPath + '\' + $siteName + '-' + (Get-Date -Format "yyyyMMdd").ToString() + '-app-web.config'
    "Backing up app-web.config to :: " + $appConfigFileBackup
    Copy-Item $appConfigFile -Destination $appConfigFileBackup

$siteConfigFileBackup = $backupPath + '\' + $siteName + '-' + (Get-Date -Format "yyyyMMdd").ToString() + '-site-web.config'
    "Backing up site-web.config to :: " + $siteConfigFileBackup
    Copy-Item $siteConfigFile -Destination $siteConfigFileBackup

$appLogoFileBackup = $backupPath + '\' + $siteName + '-' + (Get-Date -Format "yyyyMMdd").ToString() + '-Cortex-app-logo.png'
    "Backing up Cortex-app-logo.png to :: " + $appLogoFileBackup
    Copy-Item $appLogoFile -Destination $appLogoFileBackup

###### Backup the SQL DB #####
$sqlScriptedBackupFileName = $backupPath + '\' + $siteName + '-' + (Get-Date -Format "yyyyMMdd").ToString() + '.bak'
    $sqlBackup = "BACKUP DATABASE [" + $sqlDbName + "] TO DISK = '" + $sqlScriptedBackupFileName + "'"
    "Backing up current SQL DB :: " + $sqlBackup
    Invoke-Sqlcmd -Query $sqlBackup -ServerInstance $sqlInstance -QueryTimeout 0


###### Backup the MongoDB database #####
$cmdline = $mongoDir + '\mongodump.exe'
    $mongoScriptedBackupFileName = $backupPath + '\' + $siteName + '.mongodb'+ (Get-Date -Format "yyyyMMdd").ToString() + '.archive'
    $cmdargs = ' --archive=' + $mongoScriptedBackupFileName + ' --db ' + $mongoDbName + ' --gzip'

    If($mongoAuthEnabled -eq 1) {
        $cmdargs = $cmdargs + ' /u ' + $mongoUsr + ' /p ' + $mongoPwd + ' --port=' + $mongoDBPort
      }  Else {$cmdargs = $cmdargs}

    "Archiving current MongoDB :: " + $cmdline + $cmdargs
    Start-Process -FilePath $cmdline -ArgumentList $cmdargs -Wait

###### Start the IIS (Website) #####
Start-WebSite $siteName

####################################################
##################### END ##########################
####################################################


If you require assistance, please let us know.


The End.