HomeDev GuideAPI Reference
Dev GuideAPI ReferenceLegal TermsDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Export and import database

Describes how to export and import a database for each environment, follow the retention hours, and use the API for Optimizely Digital Experience Platform (DXP).

You can export the Optimizely Content Management System (CMS) or Optimizely Customized Commerce database to a bacpac file using the API or using the PaaS portal.

When you export a database, it triggers an export job for the requested database. The export job copies the requested database from the requested environment to a database in the Integration environment to avoid performance issues in the production environment when the export runs. It then exports to a bacpac file from the copied database and stores it on BLOB storage.

📘

Note

The export or import database process can take from a few hours to several days (in extreme cases). You can export only one database at a time.

The following sections describe operations to export the database to a .bacpac file using the API.

Export database

Request

POST api/v1.0/projects/{projectId}/environments/{environment}/databases/{databaseName}/exports

Parameters

NameTypeDescription
databaseNamestringThe name of the requested database

Valid names: epicms, epicommerce
environmentstringThe name of the environment of the requested database
projectIdGuidThe identifier of the project of the requested database

Body

{
  retentionHours : 12             
}
NameTypeDescription
retentionHoursintTotal hours that the bacpac is retained in the bacpacs container

Default value: 24

Response

{
  Id           : guid,
  projectId    : guid,
  environment  : string,
  databaseName : string,
  status       : string,
  downloadLink : string                                                         
}

Get export database

This API gets the information about the export job triggered by an export database operation.

Request

GET api/v1.0/projects/{projectId}/environments/{environment}/databases/{databaseName}/exports/id

Parameter

NameTypeDescription
idGuidThe identifier of the export job

Response

(Same as a response for Export database operation.)

{
  Id           : guid,
  projectId    : guid,
  environment  : string,
  databaseName : string,
  status       : string,
  downloadLink : string                                                         
}

Import database

Importing a database is considered a deployment and is only available for integration and additional environments.

Database package naming convention

<app name>.<package type>.sqldb.<version>.bacpac
  • App name – Optional. Must not contain spaces or special characters.
  • Package types – Valid package types are:
    • cms (primary web app)
    • commerce (commerce manager)
  • Version – You can specify it differently, using a date format or a version number.

The SQL DB packages should be the bacpac file for the database because this is already a compressed file (zip file with a bacpac extension). Nothing more is needed.

Example: myapp.commerce.sqldb.1.0.0.bacpac

Using deployment API to import database

Add credentials to the PowerShell scope; see Deploy using PowerShell.

Connect-EpiCloud -ClientKey <ClientKey> -ClientSecret <ClientSecret> -ProjectId <ProjectId>

To upload a database package to your DXP project, run Get-EpiDeploymentPackageLocation to get the SAS link where the package should be uploaded and Add-EpiDeploymentPackage to upload that package.

$saslink = Get-EpiDeploymentPackageLocation  
Add-EpiDeploymentPackage -SasUrl $saslink -Path C:\\MyDeploymentPackages\\myapp.commerce.sqldb.1.0.0.bacpac

The bacpac file is now available to be imported to a target environment.

To import databases to a target environment, use the following command:

Start-EpiDeployment -DeploymentPackage @('myapp.commerce.sqldb.1.0.0.bacpac') -TargetEnvironment Integration -DirectDeploy

To get the details of a specific import database deployment, specify the ID of that deployment. It returns the same type of object as Start-EpiDeployment.

PS> Get-EpiDeployment -Id 2a52c873-b39c-4f44-b842-aab5009c3060
 
id                 : 2a52c873-b39c-4f44-b842-aab5009c3060
projectId          : 2a561398-d517-4634-9bc4-aab5008a8e1a
status             : InProgress
startTime          : 2019-08-26T09:28:39.479Z
endTime            :
percentComplete    : 2
validationLinks    : {}
deploymentErrors   : {}
deploymentWarnings : {}
parameters         : @{targetEnvironment=Integration; packages=System.Object[]; maintenancePage=False}

Test tools

  • Postman
  • Epicloud
    • Start-EpiDatabaseExport
    • Get-EpiDatabaseExport
    • Get-EpiDeploymentPackageLocation
    • Add-EpiDeploymentPackage
    • Start-EpiDeployment
  • Swagger
    • swagger/ui/index