December 2, 2022 at 12:50
filed under Dynamics AX
Hi all,
We had a requirement to automatically create a backup of the database of a Tier 2 environment. Luckily there is the Database Movement API that allows you to do just that.
In his excellent blog post Automated backups of D365FO databases, Dick explains how to set this up using Release pipelines. We have done the same, but using (build) pipelines, so that’s what is documented below.
There are only minor differences. For example we use an output variable for pass the token between tasks, but for the rest everything is pretty much the same. So thank you Dick.
A new pipeline is created:
Before you start, you need to create an application registration and have an account. See Step 1 to Step 3 on this page: Database movement API – Authentication.
After this is done, on your pipeline, click on the Variables tab. Add the following variables:
CLIENTID, CLIENTSECRET, GOLDEN (or ACCEPT, MIGRATION, etc., depending on your environment), LCSPROJID, PASSWORD, USERNAME.
CLIENTID | This is the client ID from your application registration |
CLIENTSECRET | This is the client secret from your application registration |
GOLDEN | This is the Environment Id of the environment you want to create a backup for. You can find this on the Environment details page in LCS. |
LCSPROJID | You can find the project id in the URL when you are on the project in LCS. It’s an integer like 1234567. |
USERNAME | The email address of the service account you will use for this operation |
PASSWORD | The password of the service account |
It should look something like this:
Don’t worry, all data is fake in the screenshot :).
Next on the Output Variables fast tab, set the reference name to task1.
It should look like this:
Next well add the task that will perform a backup of our environment. Repeat the same steps as before to add the PowerShell task but name it Backup database Golden.
Set the inline script to:
Our pipeline will look like this:
On the Triggers tab, click on Add in the Scheduled section. Choose you schedule and unmark the checkbox Only schedule builds if the source or pipeline has changed.
Click on Save & Queue, the click on Save.
That’s it, your pipeline will create a backup for this environment based on your schedule. You should see your backup in the Asset library on LCS when the pipeline has run.
Kristof Meesens
on December 2, 2022 at 12:57
Thanks for sharing this Klaas!