Export and import database
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
Name | Type | Description |
|---|---|---|
databaseName | string | The name of the requested database Valid names: epicms, epicommerce |
environment | string | The name of the environment of the requested database |
projectId | Guid | The identifier of the project of the requested database |
Body
{
retentionHours : 12
}Name | Type | Description |
|---|---|---|
retentionHours | int | Total 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
Name | Type | Description |
|---|---|---|
id | Guid | The 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
Import database with Deployment API
Add credentials to the PowerShell scope; see Deploy using PowerShellDeploy 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.bacpacThe 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 -DirectDeployThis replaces an existing database.
Start-EpiDeployment returns details of the deployment, including the deployment ID. 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