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

Dynamics NAV - All that you need to know about MenuSuites.

Hi Readers, This article is based on a request from a blog reader who wanted to understand about MenuSuite in Dynamics NAV. If you have started working with Business central with AL Code then it does not apply to those releases but if you are interested go ahead. Let's start with Future - In Latest and greatest version of product MenuSuite are obsolete and no longer used. So this article applies if you want to learn about C/AL MenuSuite.

How to Set Up NavUserPassword Authentication in Business Central.

Hi Readers, In this article we will discuss steps to Setup NAVUserPassword in Business Central on-prem. NavUserPassword is an authentication method that's handled by Business Central Server, but isn't based on Windows users or Active Directory. Each user is set up with a username and password that's configured inside Business Central only. The user is prompted for username/password credentials when they start the client. #msdyn365bc, #credentialtype

Microsoft Dynamics NAV 2016 - How to Configure Phone Client.

Hi All, In this article we will discuss how we can connect Microsoft Dynamics NAV 2016 with New Client Launched i.e. Phone Client. This Article Contain Steps for a Android Phone as I have Only Android Phone. I am doing it having all tiers on my windows 8 machine, steps remain same for multiple servers but issues might be different. What we Need (Other what we discuss in this article) -  The Service Tier should be on Public IP . Some of the Data-card does not Provide you Public IP. check it for sure.