Applicable products

√ Cortex Project History 1.x

√ Cortex 365


Prerequisites

  • Administrative rights on the Cortex host server


Assumptions

  • IIS, SQL and MongoDB may be on different servers.
  • This script must be run from the SQL Server.


Overview

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

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

  • 6 & 7
  • 11, 12 & 14
  • 22 & 24
  • 27, 29, 31 & 33
  • 35 & 36
  • 86 (uncomment to cleanup the target folder)

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

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

# Enter the path to the backup Root folder.
# $backupRoot = 'F:\Backup_Root' 
$backupRoot = '\\SERVERNAME\d$\Backup_Root' # alternate UNC Path 

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

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

# Enter the path to the MongoDB Tools folder. (ex: mongodb-database-tools-windows-x86_64-100.6.1\bin)
$mongoDir = 'C:\temp\mongodb-database-tools-windows-x86_64-100.6.1\bin'
# Enter the MongoDB name.
$mongoDbName = 'EosCortexCLI01'
# Enter the MongoDB username.
$mongoUser = 'EosCortex01'
# Enter the MongoDB user password.
$mongoPwd = 'SOME_STRONG_PASSWORD'
# Enter the MongoDB Server IP and Port.
$mongoDBip = '10.110.10.10'
$mongoDBport = '27017'

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

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

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

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

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

$appLogoFileBackup = $backupPath + '\' + $siteName + '-' + (Get-Date -Format "yyyyMMdd.HHmmss").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.HHmmss").ToString() + '-SQL.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 + '-' + (Get-Date -Format "yyyyMMdd.HHmmss").ToString() + '-mongodb.archive'
    $cmdargs = ' --archive="' + $mongoScriptedBackupFileName + '" --gzip' + ' --uri '
    $mongoURI = ' "' + 'mongodb://' + $mongoUser + ':' + $mongoPwd + '@' + $mongoDBip + ':' + $mongoDBport + '/' + $mongoDbName + '"'
    $cmdargs = $cmdargs + $mongoURI
    "Archiving current MongoDB :: " + $cmdline + $cmdargs
    Start-Process -FilePath $cmdline -ArgumentList $cmdargs -Wait

###### Compress and create a .zip file #####
$ZipFileName = 'bkp_' + $siteName + '_' + (Get-Date -Format "yyyyMMdd.HHmmss").ToString() + '.zip'
$ZipFileDestination = $backupRoot + '\' + $ZipFileName
    "Creating Zip file ::"
    Compress-Archive -Path $backupPath -DestinationPath $ZipFileDestination

###### Delete original destination folder #####
# uncomment out the following line to cleanup the target folder
# Remove-Item -LiteralPath $backupPath -Force -Recurse


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


If you require assistance, please let us know.


The End.