# wip-backup-manager

> This utility enables backup & restore of Kentico Kontent projects

Latest version **0.0.9** (published 2020-04-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install wip-backup-manager
pnpm add wip-backup-manager
yarn add wip-backup-manager
bun add wip-backup-manager
```

Provides the command `kbm`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2020-04-08 |
| First published | 2020-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 289.7 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 7 |
| Author | richard sustek |
| Maintainers | enngage |
| Keywords | Kentico, Kontent, Kentico Kontent, Kontent backup manager, Kontent restore project, Kontent backup project, Kontent import |

## Links

- npm: https://www.npmjs.com/package/wip-backup-manager
- Repository: https://github.com/Enngage/kontent-backup-manager
- Homepage: https://github.com/Enngage/kontent-backup-manager#readme
- Issues: https://github.com/Enngage/kontent-backup-manager/issues
- npm.io page: https://npm.io/package/wip-backup-manager

## Dependencies (5)

- [rxjs](https://npm.io/package/rxjs.md) 6.5.5
- [jszip](https://npm.io/package/jszip.md) 3.3.0
- [yargs](https://npm.io/package/yargs.md) 15.3.1
- [flatted](https://npm.io/package/flatted.md) 2.0.2
- [@kentico/kontent-management](https://npm.io/package/@kentico/kontent-management.md) 0.3.18

## Recent versions

- 0.0.9 (latest) — 2020-04-08
- 0.0.8 — 2020-04-08
- 0.0.6 — 2020-04-02
- 0.0.5 — 2020-03-23
- 0.0.4 — 2020-03-11
- 0.0.3 — 2020-02-28
- 0.0.2 — 2020-02-28
- 0.0.1 — 2020-02-28

## README

# Kontent Backup Manager

The purpose of this project is to backup & restore [Kentico Kontent](https://kontent.ai) projects. This project uses CM API to both get & restore data.

## Installation

Install package globally:

`npm i wip-backup-manager -g`

## Use via CLI

### Configuration

| Config          | Value                                                                                                               |
|-----------------|---------------------------------------------------------------------------------------------------------------------|
| **projectId**       | Id of Kentico Kontent project **(required)**                                                                            |
| **apiKey**           | Content management Api key **(required)**                                                                               |
| **action**           | Action. Possible values are: 'restore' & 'backup' & 'clean' **(required)**                                              |
| zipFilename     | Name of zip used for export / restoring data. E.g. 'kontent-backup'.                                            |
| enableLog       | Indicates if default logging is enabled (useful to indicate progress)       
| force           | If enabled, project will we exported / restored even if there are data inconsistencies. Enabled by default. |


### 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`

### Use with config file

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

```json
{
    "projectId": "xxx",
    "apiKey": "xxx",
    "zipFilename": "backup",
    "action": "backup",
    "enableLog": true,
    "force": true
}
```

To execute your action run: 

`kbm --config=backup-config.json`

## Use via code

### Backup in code

```typescript
const run = async () => {
    const exportService = new ExportService({
        apiKey: 'sourceProjectApiKey',
        projectId: 'sourceProjectId',
        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

```typescript
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}`);
        },
        fixLanguages: true,
        projectId: 'targetProjectId',
        apiKey: 'targetProjectId',
        enableLog: true,
        workflowIdForImportedItems: '00000000-0000-0000-0000-000000000000' // workflow 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

```typescript
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}`);
        },
        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();
```

---
_Source: https://npm.io/package/wip-backup-manager · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
