Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kentico/kontent-backup-manager

Package Overview
Dependencies
Maintainers
11
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kentico/kontent-backup-manager

This utility enables backup & restore of Kentico Kontent projects

  • 3.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
52
increased by10.64%
Maintainers
11
Weekly downloads
 
Created
Source

npm version CircleCI Build & Test

Kontent Backup Manager

The purpose of this project is to backup & restore Kentico Kontent projects. This project uses CM API to both get & restore data.

Installation

Install package globally:

npm i @kentico/kontent-backup-manager -g

Use via CLI

Configuration

ConfigValue
projectIdId of Kentico Kontent project (required)
apiKeyContent management Api key (required)
actionAction. Possible values are: restore & backup & clean (required)
zipFilenameName of zip used for export / restoring data. (e.g. 'kontent-backup').
enableLogIndicates if default logging is enabled (useful to indicate progress)
forceIf enabled, project will we exported / restored even if there are data inconsistencies. Enabled by default.
baseUrlCustom base URL for Management API calls.
enablePublishIndicates if language variants published on the source project are also published on target. Enabled by default
exportFilterCan be used to export only selected data types. Expects CSV of types. For example contentType,language will cause backup manager to export only content types & language data. List of data types can be found below.

Data types

  • taxonomy
  • contentType
  • contentTypeSnippet
  • contentItem
  • languageVariant
  • language
  • assetFolder
  • binaryFile
  • workflowSteps (only export)

Execution

We recommend restoring backups to clean (empty) projects. Restoration process may make changes to target project such as changing language codenames to match source project.

To backup a project run:

kbm --action=backup --apiKey=xxx --projectId=xxx

To restore a project run:

kbm --action=restore --apiKey=xxx --projectId=xxx --zipFilename=backupFile

To clean (delete) everything inside a project run:

kbm --action=clean --apiKey=xxx --projectId=xxx

To get some help you can use:

kbm --help

Use with config file

Create a json configuration file in the folder where you are attempting to run script. (e.g. backup-config.json)

{
    "projectId": "xxx",
    "apiKey": "xxx",
    "zipFilename": "backup",
    "action": "backup",
    "enableLog": true,
    "force": true,
    "baseUrl": null,
    "exportFilter: null
}

To execute your action run:

kbm --config=backup-config.json

Use via code

Backup in code

const run = async () => {
    const exportService = new ExportService({
        apiKey: 'sourceProjectApiKey',
        projectId: 'sourceProjectId',
        exportFilter: undefined,
        onExport: item => {
            // called when any content is exported
            console.log(`Exported: ${item.title} | ${item.type}`);
        }
    });

    // data contains entire project content
    const data = await exportService.exportAllAsync();

    // you can also save backup in file with ZipService
    const zipService = new ZipService({
        filename: 'file',
        enableLog: true
    });

    await zipService.createZipAsync(data);
};

run();

Restore in code

const run = async () => {
    const zipService = new ZipService({
        filename: 'xxx',
        enableLog: true
    });

    const importService = new ImportService({
        onImport: item => {
            // called when any content is imported
            console.log(`Imported: ${item.title} | ${item.type}`);
        },
       canImport: {
            asset: (item) => {
                if(item.title.startsWith('_corporate')) {
                    // asset will be imported only if the title starts with "_corporate"
                    return true;
                }
                // otherwise asset will NOT be imported
                return false;
            },
            contentType: (item) => {
                if (item.codename === 'article') {
                    // content type will be imported only with its codename is 'article'
                    return true;
                }
                // all other types will be excluded from import
                return false;
            },
            assetFolder: item => true, // all folders will be imported
            contentItem: item => true, // all content items will be imported
            contentTypeSnippet: item => true, // all content type snippets will be imported
            language: item => true, // all languages will be imported
            languageVariant: item => true, // all language variants will be imported
            taxonomy: item => true,// all taxonomies will be imported
        },
        enablePublish: true, // when enables, previously published language variants will be published after restore (does not affect unpublished variants)
        projectId: 'targetProjectId',
        apiKey: 'targetProjectId',
        enableLog: true, // shows progress of immport in console
        fixLanguages: true, // backup manager will attempt to create missing languages & map existing languages
        workflowIdForImportedItems: '00000000-0000-0000-0000-000000000000' // id that items are assigned
    });

    // read export data from zip
    const data = await zipService.extractZipAsync();

    // restore into target project
    await importService.importFromSourceAsync(data);
};

run();

Clean in code

const run = async () => {
    const zipService = new ZipService({
        filename: 'xxx',
        enableLog: true,
        context: 'node.js' // 'node.js' or 'browser'
    });

    const importService = new ImportService({
        onDelete: item => {
            // called when any content is deleted
            console.log(`Deleted: ${item.title} | ${item.type}`);
        },
        fixLanguages: true,
        projectId: 'targetProjectId',
        apiKey: 'targetProjectId',
        enableLog: true
    });

    // read export data from zip
    const data = await zipService.extractZipAsync();

    // restore into target project
    await importService.importFromSourceAsync(data);
};

run();

Keywords

FAQs

Package last updated on 24 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc