If there is something that changes in NAV every few releases, is how we backup and restore data (be that full backup, application data, companies data) between NAV databases.
Recently I was asked how is this done in NAV 2016.
The answer is simple and is applicable to both NAV 2015 and NAV 2016:
- with 2 powershell cmdlets
- via Pages 9901 (for Export) and Page 9900 (for Import)
- using C/AL functions EXPORTDATA/IMPORTDATA.
Let’s assume the following case. A bug was reported by a customer. You want to have access to his production environment, but many times that’s not possible. One way is to do a SQL backup of customer’s database. That assumes you will have at least backup rights on their database server. Many times that’s not possible. But you probably have access to NAV.
Let’s try to export company data with powershell cmdlets:
- Launch Dynamics 2016 Administration Shell
- Run the following cmdlet:
- DatabaseName : look in the NAV Administration console for the database name associated with your instance
- FilePath: it is expected a file with extension “navdata”
- Copy navdata file onto your local machine and run the following cmdlet to restore the company data in your other environment (be that development, or QA …)
- Similarly to the previous step, DatabaseName can be extracted from the NAV Administration console and FilePath is a local file with a “navdata” extension
- The cmdlet is confirming that we want to overwrite the company “…” on the local server “.\ServerName”
- After confirmation of the overwrite, the importing starts, but we get an error. The cmdlet reports that there is a difference in a table definition. In the example above, on the destination database, one of the tables had a few new fields, just because the destination environment was a development copy of customer’s database.
- To get around this error you need to have similar objects on the destination and the source. So I saved the latest changes on the target database (exported to a fob) calling it LatestChanges.fob. Then I sync’d objects from customer production with target database. I re-run again Import-NAVData and this time it run without issues.
- After a succesful import of company data you can restore your code from LatestChanges.fob
- The easiest way though, to restore a company data, is to use Page 9901 (for Export)on the Source and Page 9900 (for Import) on the Target.
To export/import data via C/AL code check EXPORTDATA and IMPORTDATA functions:
Msdn EXPORTDATA and Msdn IMPORTDATA
For a sample of how to use these 2 functions, check the code in pages 9900, 9901 in W1.
Original post here.