Restore MX Cloud database into your local development environment

This assumes that you have a Mendix project downloaded in Mendix Studio Pro (Modeler) and that the same project is deployed to a Mendix Cloud node.

Via the UX

Note

The following program versions were used for this guide:

  • PostgreSQL v12.1.3, Windows 64 bit
  • DBeaver CE v6.3.0, Windows 32/64bit
  • 7-Zip v19.00 Windows 64 bit

Download and install PostgreSQL

  1. Download the installer from https://www.enterprisedb.com/thank-you-downloading-postgresql?anid=1257093 (or check at https://www.postgresql.org/download/windows/ for the latest version).
  2. Run the installer as Administrator. If you get a UAC prompt, click “Yes”.
  3. When the setup wizard starts, click “Next >”.
  4. Leave the default installation directory alone (C:\Program Files\PostgreSQL\12) and click “Next >”.
  5. Uncheck everything except “PostgreSQL Server” and “Command Line Tools” then click “Next >”.
  6. Leave the default data directory alone (C:\Program Files\PostgreSQL\12\data) and click “Next >”.
  7. Enter “postgres” in both password boxes and click “Next >”.
  8. Leave the default port (5432) and click “Next >”.
  9. Leave the locale as “[Default locale]” and click “Next >”.
  10. Check the settings and click “Next >”.
  11. Click “Next >”.
  12. Wait for the installation to finish then click “Finish”.

Download and install DBeaver

  1. Download the installer from https://dbeaver.io/files/dbeaver-ce-latest-x86_64-setup.exe (or check at https://dbeaver.io/download/ for the latest version).
  2. Run the installer as Administrator. If you get a UAC prompt, click “Yes”.
  3. When the setup wizard starts, leave the language as “English” and click “Next >”.
  4. On the welcome screen, clickj “Next >”.
  5. Read the license if you want, then click “I Agree”.
  6. Leave “For anyone who uses this computer (all users)” selected and click “Next >”.
  7. Leave “DBeaver Community” checked and everything else unchecked and click “Next >”.
  8. Leave the installation directory alone (C:\Program Files\DBeaver) and click “Next >”.
  9. Leave the shortcut name as “DBeaver Community” and click “Install”.
  10. Wait for the installation to finish then click “Finish”.

Download and install 7-Zip

  1. Download the installer from https://www.7-zip.org/a/7z1900-x64.exe (or check at https://www.7-zip.org/download.html for the latest version).
  2. Run the installer as Administrator. If you get a UAC prompt, click “Yes”.
  3. Leave the default installation directory alone (C:\Program Files\7-Zip) and click “Install”.
  4. When the installation is complete, click “Close”.

Aquire a backup from the MX Cloud

  1. Browse to https://cloud.home.mendix.com/
  2. Click the “Details” button on the app you are working with
  3. From the left hand navigation, select “Backups”
  4. Use the select box to choose which environment to take the backup from
  5. Click the “Create backup” button
  6. When the backup has completed, select it and click the “Download backup” button
  7. Leave “Full snapshot” selected then click the “Start” button
  8. When the backup has been packaged, click the “Download” button
  9. Choose a location for the download and click “Save”
  10. Go to the download location, right-click the file and select 7-Zip > Extract here.
  11. When the extration has finished, right-click the resulting .tar file and select 7-Zip > Extract to {name of file}.

Copy uploaded files into the Mendix Deployment directory

  1. Open the directory that was created in the last step and then open the “tree” subdirectory.
  2. Select all files and folders in the directory, right-click and select “Copy” (or do Ctrl+A then Ctrl+C).
  3. Now open your Mendix Project directory, open the “deployment” subdirectory and then the “files” subdirectory.
  4. Now right-click and select “Paste” (or do Ctrl+V) to copy the backed up files into your project.

Create a new database and restore the backup using DBeaver

  1. Click the Start button then type “DBeaver” and click the resulting application to start DBeaver.
  2. The program should start with the “Connect to database dialog” open, but if not you can launch it from Database > New Database Connection.
  3. Select the “PostgreSQL” icon and click “Next >”.
  4. Make sure that the username and password are both “postgres” before clicking “Finish”.
  5. Download any drivers that are missing where prompted.
  6. In the “Database Navigator” panel on the left, right click the database server labeled “PostgreSQL - postgres” and select Create > Database.
  7. Give your new database a suitable app specific name and click “OK”.
  8. In the “Database Navigator” panel, right-click your new database and select Tools > Restore.
  9. When the Restore wizard has started, click the small folder icon to select the “Backup file” (it is in the directory you extracted under the db subdirectory).
  10. Enter “–no-owner” in the “Extra command args” box, then click “Start”.
  11. When the backup is complete, click “Cancel” to close the dialog (You may notice an error like “Process exit code: 1”. This is likely from the very start of the restore due the the scheme “public” already existing on the database. You can safely ignore it.).
  12. Close DBeaver.

Configure your project to use the new data

  1. Open your project in Mendix Studio Pro (Modeler).
  2. In the “Project Explorer” panel, expand the top level “Project” node and double-click “Settings” to open the Project Settings dialog.
  3. Under the “Configurations” tab, click the “New” button.
  4. In the New Configuration dialog:
    • Give it a meaningful name;
    • Change the “Type” to “PostgreSQL”;
    • Change the “URL” to “localhost:5432”;
    • Change the “Database name” to the one you chose in the previous section;
    • Set the “User name” to “postgres” and set the “Password” to “postgres” as well.
  5. Click “OK”.
           /.\
          // \\
         //  o\\
        //\/ \ \\
       /=========\

WORK IN PROGRESS

Via the API in PowerShell

Via the API in bash (or similar shell)

username = ‘’ apikey = ‘’ appid = ‘’ environment = ‘test’

reply = curl –header “Content-Type: application/json”
–header “Mendix-Username: $username”
–header “Mendix-ApiKey: $apikey”
“https://deploy.mendix.com/api/1/apps/$appid/environments/$Environment/snapshots”

  1. Take a snapshot HTTP Method: POST URL: https://deploy.mendix.com/api/1/apps/{AppId}/environments/{Environment}/snapshots Headers: Content-Type: application/json Mendix-Username: {Your username} Mendix-ApiKey: {Your ApiKey}
Reply body:
{
	"SnapshotID": "0c982ca3-621f-40e9-9c6e-96492934170a",
	"Comment": "My user comment",
	"State": "Completed",
	"ExpiresOn": 1530868721000,
	"CreatedOn": 1523006321000,
	"ModelVersion": "1.0.11.50"
}
  1. Prepare a download package HTTP Method: GET URL: https://deploy.mendix.com/api/1/apps/{AppId}/environments/{Environment}/snapshots/{SnapshotId} Headers: Content-Type: application/json Mendix-Username: {Your username} Mendix-ApiKey: {Your ApiKey}
Reply body:
{
	"FilesOnly": "https://cloud.home.mendix.com/backups/d4bf9d5d-cf3e-4561-9f7f-31b1c580a3d5",
	"DatabaseOnly": "https://cloud.home.mendix.com/backups/5524ec0b-fdf1-460b-87c2-75bb06ec98ff",
	"DatabaseAndFiles": "https://cloud.home.mendix.com/backups/24783a6c-30c4-49b4-8cb9-13b57cfec4cc"
}
  1. Download the package wget