Skip to main content

NAV 2013 R2 - Restore a Multi Tenant Environment.

Hi all,

We had seen how to create a Multi Tenant Environment & How to Backup the Complete Environment with NAV 2013 R2 in the respective articles.

But what if i want to do a restore backup of the Multi Tenant Environment in a Different Server. How can i achieve it as in my SQL now i have multiple databases.

So let's see how we can achieve it.

** References - Waldo Blog. Thanks to Waldo for sharing the Information, i have tried to append the steps listed in the Video.

Scenario -
I took backup of My Multi tenant Environment Created with Multiple Tenants (5) and Application Objects. I want to Restore the whole Environment and Restore it on New Server.



Steps - (Before Starting the process, lets see the environment creation steps)x

1. Created a Service MultiTenantRestore as shown Below.



2. Copy the databases backup on the new server where you want to restore as shown below.



3. For Restore all the Tenant and Application database from a Specified Location, i have used Below Powershell Command.
* Powershell should be Run as Administrator. How to Open Powershell.

--------------------------------------------------------------------------------------
# Powershell Command to Restore Backup of Tenant and Application Database.
# Author - Waldo
# Modified By - Saurav Dhyani
# Blog - saurav-nav.blogspot.com
# Parameters Need to Specify Before Running Command -
# Backups - Directory Path where backups have been placed with file extension *.bak. (Currently Set to D:\Tenants Backups\*.bak)
# fileloc - Directory Path for data file to get restored. (D:\Tenants\data)
# logloc -  Directory Path for log file to get restored. (D:\Tenants\log)

$Backups = dir 'D:\Tenants Backups\*.bak'
$fileloc = 'D:\Tenants\data'
$logloc  = 'D:\Tenants\log'

Set-NAVServerInstance MultiTenantRestore -stop

foreach ($BackupFile in $Backups) {
 'Restoring ' + $BackupFile.Directory + '\' + $BackupFile.Name

 $server = New-Object Microsoft.SqlServer.Management.Smo.Server localhost
 $backupDevice = New-Object Microsoft.SqlServer.Management.Smo.BackupDeviceItem $BackupFile, "File"
 $Restore = New-object Microsoft.SqlServer.Management.Smo.Restore

 #Set properties for Restore
 $Restore.NoRecovery = $false;
 $Restore.ReplaceDatabase = $true;
 $Restore.Devices.Add($backupDevice)
 $RestoreDetails = $Restore.ReadBackupHeader($server)
 $Restore.Database = Get-ChildItem $BackupFile | % {$_.BaseName}

 $dbname = Get-ChildItem $BackupFile | % {$_.BaseName}
 $files = $restore.ReadFileList($server)

 foreach ($file in $files)
 {
  $rsfile = new-object Microsoft.SqlServer.Management.Smo.RelocateFile
  $rsfile.LogicalFileName = $file.LogicalName


  $dbfile = $fileloc + '\'+ $dbname + '_Data.mdf'
  $logfile = $logloc + '\'+ $dbname + '_Log.ldf'

  if ($file.Type -eq 'D') {
    $rsfile.PhysicalFileName = $dbfile
  }
  else {
    $rsfile.PhysicalFileName = $logfile
  }
 $restore.RelocateFiles.Add($rsfile)
 }

 $Restore.SqlRestore($server)
}
--------------------------------------------------------------------------------------

You can download the Powershell command from the Sky Drive Link. Link is available at end of the Post.

4. Let's Understand the Command.
At the Beginning of the Command we set two Parameters i.e -

1. $Backups = dir 'D:\Tenants Backups\*.bak' (Directory Path where backups have been placed with file extension *.bak.)
2. $fileloc = 'D:\Tenants\data' (Directory Path for data file to get restored.)
3. $logloc  = 'D:\Tenants\log' (Directory Path for log file to get restored.)

Next i stopped the Service Instance which i will be using to mount my Application.

Then For Every .bak file in the Backup Directory,  i used the SQLPS Restore Commandlet to Restore the backup into the Server with certain properties set while restoring.
At the End i Placed the Data and Log file as per the parameter specified at the top of the commandlet.

5. When i executed the command, lets see what i get as output in Powershell.



6. Let's open SQL and check the database are they restored or not.


7. Now the task left is to set the service instance properties, let's do it from power shell.
--------------------------------------------------------------------------
# Powershell Command to Set service Instance to MultiTenancy.
# Author - Saurav Dhyani
# Blog - saurav-nav.blogspot.com
# Replace Server Name with Actual Server Name

Set-NAVServerConfiguration -ServerInstance MultiTenantRestore -KeyName MultiTenant -KeyValue "true"
Set-NAVServerConfiguration -ServerInstance MultiTenantRestore -KeyName DatabaseName -KeyValue ""
Set-NAVServerConfiguration MultiTenantRestore -Start

Mount-NAVApplication -DatabaseServer "<<SERVER NAME>>" -DatabaseName "MultiTenant_Application_Database" -ServerInstance MultiTenantRestore
Mount-NAVTenant -ServerInstance MultiTenantRestore -Id mytenant1 -DatabaseName "MyTenant1" -OverWriteTenantIDInDatabase
Mount-NAVTenant -ServerInstance MultiTenantRestore -Id mytenant2 -DatabaseName "MyTenant2" -OverWriteTenantIDInDatabase
Mount-NAVTenant -ServerInstance MultiTenantRestore -Id mytenant3 -DatabaseName "MyTenant3" -OverWriteTenantIDInDatabase
Mount-NAVTenant -ServerInstance MultiTenantRestore -Id mytenant4 -DatabaseName "MyTenant4" -OverWriteTenantIDInDatabase
Mount-NAVTenant -ServerInstance MultiTenantRestore -Id mytenant5 -DatabaseName "MyTenant5" -OverWriteTenantIDInDatabase

Set-NAVServerConfiguration MultiTenantRestore -Stop
Set-NAVServerConfiugration MultiTenantRestore -Start
-----------------------------------------------------------------------------
You can download the Powershell command from the Sky Drive Link. Link is available at end of the Post.


8. Let's try to understand what i am doing in above commandlet.

1. I Set the Service Instance as MultiTenant and remove the database Name from Service Instance. Then i start the service instance.
2. After that i mounted the application database on the service instance and after that mounted all tenats in the service instance.
3. After that i stop and started the service.

9. Let's navigate to administrative panel and check the service instance.



So i guess we have completed what we started successfully.

You can download the Powershell command from my SkyDrive.

File Name - Command 8 - NAV 2013 R2 - Restore a Multi Tenant Environment.
File Name - Command 9 - NAV 2013 R2 - Setting up Service Instance for Multi Tenant Environment.

Hope you find the information useful.

Regards,
Saurav Dhyani 
www.sauravdhyani.com

Comments

Popular posts from this blog

BC 21 and Higher - PowerShell Cmdlet (Replacement of Business Central Administration).

Hi Readers, As discussed in last article about deprecating of Business Central Administration, there are few common actions that we use in administration till Business Central 20. For our on-prem customers, we will still require doing activities. As Microsoft suggest we need to start using PowerShell cmdlet.    Let's see how to do those via PowerShell, or Administration Shell. I will be keep adding commands as you comment to this article.

Send Mail with Attachment From Navision.

Hi all, We have seen how to save a report into PDF and how to send mail to a customer. Let's link these two post in one i.e. Mailing statement to a customer into PDF Format. This article is part of the Series. Please Refer  Table of Content here . If you have the old objects set let me brief you what I will be changing - 

MSDYN365BC - Data Upgrade To Microsoft Dynamics 365 Business Central on premises.

Hi Readers, We have already talked about the number of steps for upgrading to Business Central on Premises from different NAV versions. After that article, I received multiple requests for an article which list down steps for Data Migration. In this article, we will discuss steps of data migration to MSDYN365BC (on-Prem) from NAV 2017. For this article, I am considering a Cronus Demo Database without any customization. For an actual upgrade project, we will have to complete object merge using compare and Merge process. After the Merge Process, the next step is data migration. Let's discuss those steps. Direct Upgrade to Microsoft Dynamics 365 Business Central (on-Prem) is from following versions - 1. NAV 2015. 2. NAV 2016. 3. NAV 2017. 4. NAV 2018.