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

VIEW SERVER STATE permission on SQL Server?

Hi all, Sometime While trying to Login into a database we face an error message as shown below. --------------------------- Microsoft Dynamics NAV Classic --------------------------- You cannot start Microsoft Dynamics NAV Classic because you do not have the VIEW SERVER STATE permission on SQL Server. Contact your system administrator. --------------------------- OK    ---------------------------

RTC Report It is not possible to instantiate the Visual Studio bridge.

Hi all, As a Navision developers I have Multiple Versions of Navision running in single Machine. As discussed Earlier in the post how to run multiple Version of RTC in single machine. So my machine have following details for RTC Versions - NAV 2009 R2    - is installed. NAV 2009 SP1  - is copied at C:\Program Files (x86)\Microsoft Dynamics NAV\60\NAV 6.0 SP1 IN\ NAV 2009         - is copied at C:\Program Files (x86)\Microsoft Dynamics NAV\60\NAV 6.0 IN\ This approach has been working great for execution of Classic and RTC Clients. However, after installing Dynamics NAV 2009 R2, if i tried to view the Layout for an NAV 2009 SP1 Report i was getting the following error: ---------------------------  Microsoft Dynamics NAV Classic  ---------------------------  It is not possible to instantiate  the Visual Studio bridge.  ---------------------------  OK    --------------------------- After searchi...

NAV 2013 R2 - Cumulative update 12 Released.

Hi all, Please find below the details of  Cumulative Update 12 released for Microsoft Dynamics NAV 2013 R2. Title - Cumulative Update 12 for Microsoft Dynamics NAV 2013 R2 Build No. - 38053 Release Date - October, 2014 Local Version Included - AU, AT, BE, CH, DE, DK, ES, FI, FR, IS, IT, NA, NL, NO, NZ, SE, UK, RU Download Link Note: Implementing this cumulative update will require a database conversion unless you have already implemented update rollup 5.