DataBase Move Restore Backup Tier 2(UAT) to Tier 1 (Dev)


If you want to export current database from UAT and import to Dev box, you need to goto UAT in LCS and export its database it stores in to LCS Asset Library so Then login LCS inside the Dev box use command scripts to run to turn Backpac file to bac then restore.



1. Go to LCS → UAT environment

  1. Login to LCS.

  2. Open your UAT Tier-2 environment.

  3. Go to Environment details.

  4. Scroll to Database section.

  5. Click "Point-in-time Restore / Export" or "Export database" (depends on LCS version).


2. Export the UAT DB as a BACPAC

  1. Choose Export database.

  2. Select Standard backup.

  3. Provide a name (e.g., UAT_2026_01_13).

  4. Start export.

      Export creates a BACPAC in Asset Library.

3. Download the BACPAC

  1. Once export completes, go to LCS Asset Library → Database backups.

  2. Click the backup.

  3. Download the BACPAC file.  

Note: We can create downloadable url path of bacpac file from asset library. which doesn't require credentials of LCS inside devbox. 


Import in to Dev box is 2 ways using SSMS or CMD check below.


Scenario 1. 

Import BACPAC into SQL Server (Dev Box) using SSMS

Using SQL Server Management Studio (SSMS)

  1. Open SSMS.

  2. Connect to localhost (your Dev VM SQL instance).

  3. Right-click Databases → Import Data-tier Application…

  4. Browse to downloaded .bacpac.

  5. Enter database name: 

  6. DatabaseLocation & Log location as below


                                                OR

Scenario 2. 


Step 1. 


1) firstly we need  install the  SQl package  and extract it 
Unzip and extract to a folder


Step 2.


Command for import backPack:

SqlPackage.exe /a:import /sf:D:\Exportedbacpac\my.bacpac /tsn:localhost /tdn:<target database name> /p:CommandTimeout=1200 /TargetTrustServerCertificate:True

Example prompt:

C:\sqlpackage-win-x64-en-170.2.70.1>SqlPackage.exe /a:import /sf:C:\Users\Admin012c0ab00f\Downloads\UAT01backup.bacpac /tsn:localhost /tdn:AxDB2026 /p:CommandTimeout=1200 /TargetTrustServerCertificate:True 


During import, the user name and password aren't required. By default, SQL Server uses Microsoft Windows authentication for the user who is currently signed in.

Here's an explanation of the parameters:

  • tsn (target server name) – The name of the Microsoft SQL Server instance to import into.
  • tdn (target database name) – The name of the database to import into. The database should not already exist.
  • sf (source file) – The path and name of the file to import from.

Warning (Optional): If you get any File damaged error while execution

NoteNote: If you still getting an error, download the lower version of SQLPackage.exe.


Step 3.

Update the database

Run the following SQL script against the imported database (Ex: AxDB2026). This script adds back the users that you deleted from the source database and correctly links them to the SQL logins for this SQL Server instance. The script also turns change tracking back on. Remember to edit the final ALTER DATABASE statement so that it uses the name of your database.


CREATE USER axdeployuser FROM LOGIN axdeployuser
EXEC sp_addrolemember 'db_owner', 'axdeployuser'
CREATE USER axdbadmin FROM LOGIN axdbadmin
EXEC sp_addrolemember 'db_owner', 'axdbadmin'
CREATE USER axmrruntimeuser FROM LOGIN axmrruntimeuser
EXEC sp_addrolemember 'db_datareader', 'axmrruntimeuser'
EXEC sp_addrolemember 'db_datawriter', 'axmrruntimeuser'
CREATE USER axretaildatasyncuser FROM LOGIN axretaildatasyncuser
CREATE USER axretailruntimeuser FROM LOGIN axretailruntimeuser
CREATE USER axdeployextuser FROM LOGIN axdeployextuser
CREATE USER [NT AUTHORITY\NETWORK SERVICE] FROM LOGIN [NT AUTHORITY\NETWORK SERVICE]
EXEC sp_addrolemember 'db_owner', 'NT AUTHORITY\NETWORK SERVICE'
UPDATE T1
SET T1.storageproviderid = 0
    , T1.accessinformation = ''
    , T1.modifiedby = 'Admin'
    , T1.modifieddatetime = getdate()
FROM docuvalue T1
WHERE T1.storageproviderid = 1 --Azure storage
DROP PROCEDURE IF EXISTS SP_ConfigureTablesForChangeTracking
DROP PROCEDURE IF EXISTS SP_ConfigureTablesForChangeTracking_V2
GO
-- Begin Refresh Retail FullText Catalogs
DECLARE @RFTXNAME NVARCHAR(MAX);
DECLARE @RFTXSQL NVARCHAR(MAX);
DECLARE retail_ftx CURSOR FOR
SELECT OBJECT_SCHEMA_NAME(object_id) + '.' + OBJECT_NAME(object_id) fullname FROM SYS.FULLTEXT_INDEXES
    WHERE FULLTEXT_CATALOG_ID = (SELECT TOP 1 FULLTEXT_CATALOG_ID FROM SYS.FULLTEXT_CATALOGS WHERE NAME = 'COMMERCEFULLTEXTCATALOG');
OPEN retail_ftx;
FETCH NEXT FROM retail_ftx INTO @RFTXNAME;
BEGIN TRY
    WHILE @@FETCH_STATUS = 0
    BEGIN
        PRINT 'Refreshing Full Text Index ' + @RFTXNAME;
        EXEC SP_FULLTEXT_TABLE @RFTXNAME, 'activate';
        SET @RFTXSQL = 'ALTER FULLTEXT INDEX ON ' + @RFTXNAME + ' START FULL POPULATION';
        EXEC SP_EXECUTESQL @RFTXSQL;
        FETCH NEXT FROM retail_ftx INTO @RFTXNAME;
    END
END TRY
BEGIN CATCH
    PRINT error_message()
END CATCH
CLOSE retail_ftx;
DEALLOCATE retail_ftx;
-- End Refresh Retail FullText Catalogs
--Begin create retail channel database record--
declare @ExpectedDatabaseName nvarchar(64) = 'Default';
declare @DefaultDataGroupRecId BIGINT;
declare @ExpectedDatabaseRecId BIGINT;
IF NOT EXISTS (select 1 from RETAILCONNDATABASEPROFILE where NAME = @ExpectedDatabaseName)
BEGIN
       select @DefaultDataGroupRecId = RECID from RETAILCDXDATAGROUP where NAME = 'Default';
       insert into RETAILCONNDATABASEPROFILE (DATAGROUP, NAME, CONNECTIONSTRING, DATASTORETYPE)
       values (@DefaultDataGroupRecId, @ExpectedDatabaseName, NULL, 0);
       select @ExpectedDatabaseRecId = RECID from RETAILCONNDATABASEPROFILE where NAME = @ExpectedDatabaseName;
       insert into RETAILCDXDATASTORECHANNEL (CHANNEL, DATABASEPROFILE)
       select RCT.RECID, @ExpectedDatabaseRecId from RETAILCHANNELTABLE RCT
       inner join RETAILCHANNELTABLEEXT RCTEX on RCTEX.CHANNEL = RCT.RECID
        update RETAILCHANNELTABLEEXT set LIVECHANNELDATABASE = @ExpectedDatabaseRecId where LIVECHANNELDATABASE = 0
END;
--End create retail channel database record

Note: Ignore If any errors while executing the Script Run.

4) Stop the below 4 services

  • World Wide Web Publishing Service
  • Management Reporter 2012 Process Service
  • Microsoft Dynamics 365 Unified Operations: Batch Management Service
  • Microsoft Dynamics 365 Unified Operations: Data Import Export Framework Service 

5) Rename the DB.



ALTER DATABASE AXDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE AXDB MODIFY NAME = AXDB_Orig
GO
ALTER DATABASE AXDB_Orig SET MULTI_USER
GO
ALTER DATABASE AxDB2026 SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE AxDB2026 MODIFY NAME = AxDB
GO
ALTER DATABASE AxDB SET MULTI_USER
GO

6) Start the below 4 services

  • World Wide Web Publishing Service
  • Management Reporter 2012 Process Service
  • Microsoft Dynamics 365 Unified Operations: Batch Management Service
  • Microsoft Dynamics 365 Unified Operations: Data Import Export Framework Service 

Table Browser in Dynamics 365FO

Copy D365FO Table Browser URL /?cmp=usmf&mi=SysTableBrowser&tablename= URL :  https://usnconeboxax1aos.cloud.onebox.dynamics.com...