How to Restore a D365 F&O Cloud-Hosted Environment
Note (2025): This post was written in 2018 and references VSTS (Visual Studio Team Services), which has since been renamed to Azure DevOps. The LCS-based environment provisioning described here is also evolving as Microsoft transitions management capabilities to the Power Platform admin center. The restore approach itself remains applicable to cloud-hosted Tier 1 environments.
We recently came across an issue where we needed to restore our cloud-hosted D365 Tier 1 development environment. There are similar questions in the community forums but without much detail, so we thought it would be useful to put together a short guide here.
Assuming version control is used, database backups are available, and you are an admin on the box, the restore is straightforward:
- Restore the contents of
K:\AosService\PackagesLocalDirectory - Restore the database from backup
- Run a full build and database synchronisation
A new VM can also be provisioned from scratch in LCS, but this is not always the best option — so let's look at how to repair an existing one.
Restore PackagesLocalDirectory
To restore the contents of PackagesLocalDirectory, you either need a previously created backup or clean packages from a standard VM (without any customisations), combined with a code synchronisation from your version control (VSTS). Let's look at the second option, because the first is straightforward and is part of this process anyway.
Clean packages can be taken from the build agent definition. If there is at least one build box in your LCS project, it should have a folder like J:\DynamicsBackup\Packages which contains exactly what we need. Pack it into an archive and copy it to the broken environment, then unpack it onto one of the drives — we used J:\MSSQL_BACKUP.
When ready, stop D365 services, IIS, and Reporting Services, and close Visual Studio. Open a command prompt as administrator, delete the contents of AosService\PackagesLocalDirectory, and run the following robocopy command:
robocopy J:\MSSQL_BACKUP\package K:\AosService\PackagesLocalDirectory /MIR /MT:32
Next, unlock the files by running the following PowerShell command:
dir -Path K:\AosService\PackagesLocalDirectory\ -Recurse | Unblock-File
Restore Database
Restore the database from backup using SQL Server Management Studio.
Synchronise and Build
Open Visual Studio, re-map the local directory (if needed) to your VSTS branch, and synchronise code customisations.
Restart IIS, refresh models in Visual Studio (you may need to restart VS), and run a full application build.
Note: Check the file K:\AosService\PackagesLocalDirectory\Bin\DynamicsDevConfig.xml for the correct database reference, as it may need to be updated in order to run "Update cross-references".