Friday, June 17, 2022

Tier1 database restore D365 F&O

The process of database import is needed when a new developer starts to work on a project and requires configured data for performing testing scenarios. In our projects we use preconfigured user data to improve our development and testing performance. We store a Tier 1 environment database backup (.bak) and use it when a new developer comes to work with a project.

As Microsoft releases platform updates, we need, somehow, to use old backups from environments of older versions, for data import on Tier 1 developer environments.

This instruction can be used to import and work with databases for different projects.

Import database

To import database a developer needs to have the database backup.

Important! For this operation you need to use Tier 1 database backup (.bak).

Get database backup

You need to have it to the SQLBACKUP(.bak file)  on Tier 1 DEV machine.


Create new database

Create new database in your DEV box and name it as AxDB_New


Restore the backup 

Restore the database backup in newly created databased (AxDB_New).

Run script to alter database

After performing steps above, you need to change current main database to imported one. 

To perform this operation use script below:

Code to restore database

--set main 
database to single connections and drop the existing connections 
ALTER DATABASE AxDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE

--rename database to db_old 
ALTER DATABASE AxDB MODIFY NAME = AxDB_old

--set the old database to multi user
ALTER DATABASE AxDB_old SET MULTI_USER

--rename the new database to the main database name 
ALTER DATABASE AxDB_new MODIFY NAME = AxDB

Synchronize the database

Syncrhonize the database either from Visual studio as shown below:



OR

Run the following script in PowerShell.

K:\AOSService\webroot\bin\Microsoft.Dynamics.AX.Deployment.Setup.exe
-bindir "K:\AosService\PackagesLocalDirectory"
metadatadir "K:\AosService\PackagesLocalDirectory"
-sqluser "axdbadmin" -sqlserver "." -sqldatabase "AxDB"
-setupmode "sync" -syncmode "fullall"
-isazuresql "false" -sqlpwd "*************"
-logfilename "H:\MSSQL_LOGS\AxDB_log.log"


Now your environment is ready to perform data upgrade operation.

No comments:

Post a Comment