Kontent.ai Data Ops is a powerful CLI tool designed to streamline data management in your Kontent.ai projects. It supports a wide variety of complex operations, including:
- Environment Backup: Export your project's data for backup or migration purposes.
- Environment Restore: Easily recreate environments from your backups.
- Synchronizing and Migrating Data: Keep content and content models in sync across different projects and environments.
- Executing Migration Scripts: Apply changes incrementally using migration scripts and maintain a clear history of modifications.
By automating these processes, Data Ops helps maintain consistency, reduce manual effort, and accelerate your deployment workflows.
-
Node.js: Node.js with ESM support (lts).
-
Kontent.ai Account: Access to your Kontent.ai project with appropriate permissions.
-
Management API Key: Obtain a Management API key for your project.
-
Preview Delivery API Key: For Synchronizing content, Preview Delivery API key might be required.
Security Tip: Always store your Management API keys securely. Avoid hardcoding them in scripts or sharing them publicly. Use environment variables or secure credential storage solutions when possible.
We recommend running data-ops with npx
. Be aware that npx calls the cached version of the tool. Use @latest to ensure you're using the latest version.
npx @kontent-ai/data-ops@latest <command>
Alternatively, you can install the package globally or locally:
# Global installation
npm install -g @kontent-ai/data-ops
# Local installation
npm install @kontent-ai/data-ops
Use -h
or --help
anytime to get information about available commands and their options.
npx @kontent-ai/data-ops@latest --help
# or
yarn dlx @kontent-ai/data-ops --help
# Help for a specific command
npx @kontent-ai/data-ops@latest <command> --help
# If installed globally
data-ops --help
All options (including options for commands) can be provided in three different ways:
- As command-line parameters (e.g.,
--environmentId xxx
) - In a JSON configuration file (e.g.,
--configFile params.json
) - We recommend this approach - As environment variables with
DATA_OPS_
prefix and transformed into UPPER_SNAKE_CASE (e.g.,DATA_OPS_ENVIRONMENT_ID=xxx npx @kontent-ai/data-ops ...
)
The tool usage is based on commands provided in the following format:
npx @kontent-ai/data-ops@latest <command-name> <command-options>
Below are the available commands:
- environment:
- backup & restore: Backup & restore your Kontent.ai environment.
- clean: Delete all data from your Kontent.ai environment.
- sync:
- migrate-content:
- migrations:
- add: Add new migration scripts.
- run: Execute migration scripts.
Note
All command functions are publicly exposed, making it easy to include them in your scripts. See the individual command readmes for more information.
Creating an Environment Backup including Content Items and Assets
npx @kontent-ai/data-ops@latest environment backup \
--environmentId <environment-id> \
--apiKey <Management-API-key> \
--include contentItems assets
Cleaning an Environment Excluding Taxonomies and Languages
npx @kontent-ai/data-ops@latest environment clean \
--environmentId <environment-id> \
--apiKey <Management-API-key> \
--exclude taxonomies languages
Synchronizing Content Types and Snippets Only
npx @kontent-ai/data-ops@latest sync run \
--sourceEnvironmentId <source-environment-id> \
--sourceApiKey <source-api-key> \
--targetEnvironmentId <target-environment-id> \
--targetApiKey <target-api-key> \
--entities contentTypes contentTypeSnippets
Tip
- Selective Operations: Use the
--include
option to operate on a limited set of entities. - Configuration Files: For complex commands with multiple entities, consider using a configuration file with the
--configFile
option to manage your parameters more easily.
We welcome contributions to the Kontent.ai Data Ops tool!
- Report Issues: Use the GitHub Issues to report bugs or request features.
- Fork the Repository: Create a personal fork of the repository on GitHub.
- Create a Feature Branch: Use a descriptive name for your branch.
- Submit a Pull Request: Submit your changes for review.
Please read our Contributing Guidelines for more details.
This project adheres to a Code of Conduct. By participating, you are expected to uphold this code.
- Run
npm ci
to install packages. - Run
npm run build
to compile the tool. - Run
node build/src/index.js --help
to run (ornpm run start -- --help
).
We have comprehensive test suites to ensure the reliability of the Data Ops tool.
- Unit Tests: Run
npm run test:unit
to execute unit tests. - Integration Tests: Run
npm run test:integration
to execute integration tests.
Important
Integration tests require access to a Kontent.ai project and may create temporary environments. Interrupting tests may lead to orphaned environments. Always allow tests to be completed or clean up manually if necessary.
Important
Run npm run test:advancedDiff
to compare generated advanced diffs with test baselines.
To successfully execute integration tests, you must prepare a Kontent.ai project with corresponding environments. You can use the environment restore command to import prepared zip files located at tests/integration/<testName>/data/<zipName>.zip
.
All Kontent.ai test environments are exported in tests/integration/<testName>/data/<zipName>.zip
. When you update any of these environments, you should also update the corresponding exported zip files. To streamline this process, we've provided a script called exportTestEnvironments.js
. You can run it with the command npm run export:testEnv
. If you need to export specific environments, you can use the following command parameters: -i
for Import/Export test environment, -s
for Sync Source Template environment, and -t
for Sync Target Template environment. For instance, to export only the Sync Source and Sync Target environments, you would run npm run export:testEnv -- -s -t
.
Important
Creation and removal of new environments takes some time; therefore, try to keep the number of environment-dependent tests to a minimum.
The configuration is only necessary to run the integration tests.
-
Copy the
.env.template
into.env
:cp .env.template .env
-
Fill in the values (each value is explained in comments in the template).
The main part of the tool is located in the src
folder. The project is structured around commands, with each command defined on the yargs object in a folder of the same name within the src/commands
folder. The exported register
function (of type RegisterCommand
) must be included in src/index.ts
in the commandsToRegister
array.
Tests can be found in tests/integration
and tests/unit
folders. Integration tests require Kontent.ai environments and a valid Management API key for successful execution. You can use the withTestEnvironment
function to provide the tests with a new empty environment.
This project is licensed under the MIT License - see the LICENSE.md file for details.
If you have any questions or need assistance, please reach out:
- Kontent.ai Support: Contact Support
- Kontent.ai Official Documentation: Learn more about Kontent.ai