Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add restore command inside kourou #204

Merged
merged 12 commits into from
Jan 24, 2024
65 changes: 35 additions & 30 deletions features/Elasticsearch.feature → features/Z_Elasticsearch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,7 @@ Feature: Elasticsearch commands
Then I should match stdout with "{"index": "%kuzzle.users", "alias": "@%kuzzle.users"}"

@mappings
Scenario: Insert ES document
Given a collection "nyc-open-data":"green-taxi"
When I run the command "es:indices:insert" with:
| arg | &nyc-open-data.yellow-taxi | |
| flag | --id | kindred |
| flag | --body | {} |
When I run the command "es:indices:get" with args:
| "&nyc-open-data.yellow-taxi" |
| "kindred" |
Then I should match stdout with "kindred"

Scenario: Create a snapshot repository
When I run the command "es:snapshot:create-repository" with:
| arg | backup | |
| arg | /tmp/snapshots | |
| flag | --compress | |
Then I should match stdout with "Success"

Scenario: Dump ES data to a snapshot into a repository
When I run the command "es:snapshot:create" with:
| arg | backup | |
| arg | test-snapshot | |
Then I should match stdout with "Success"

Scenario: List all available snapshot of a repository
When I run the command "es:snapshot:list" with:
| arg | backup | |
Then I should match stdout with "test-snapshot"

Scenario: Dump and restore ES data to a dump folder using the pattern option
Given an index "nyc-open-data"
Given a collection "nyc-open-data":"yellow-taxi"
Then I create the following document:
| _id | "chuon-chuon-kim" |
Expand All @@ -82,3 +52,38 @@ Feature: Elasticsearch commands
Given an existing collection "nyc-open-data":"yellow-taxi"
Then I refresh the collection
And I count 3 documents

Scenario: Insert ES document
Given a collection "nyc-open-data":"blue-taxi"
When I run the command "es:indices:insert" with:
| arg | &nyc-open-data.blue-taxi | |
| flag | --id | kindred |
| flag | --body | {} |
When I run the command "es:indices:get" with args:
| "&nyc-open-data.blue-taxi" |
| "kindred" |
Then I should match stdout with "kindred"

Scenario: Create a snapshot repository
When I run the command "es:snapshot:create-repository" with:
| arg | backup | |
| arg | /tmp/snapshots | |
| flag | --compress | |
Then I should match stdout with "Success"

Scenario: Dump ES data to a snapshot into a repository
When I run the command "es:snapshot:create" with:
| arg | backup | |
| arg | test-snapshot | |
Then I should match stdout with "Success"

Scenario: List all available snapshot of a repository
When I run the command "es:snapshot:list" with:
| arg | backup | |
Then I should match stdout with "test-snapshot"

Scenario: Restore ES data from a snapshot
When I run the command "es:snapshot:restore" with:
| arg | backup | |
| arg | test-snapshot | |
Then I should match stdout with "Success"
6 changes: 5 additions & 1 deletion src/commands/es/snapshot/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export default class EsSnapshotsCreate extends Kommand {
const esRequest = {
repository: this.args.repository,
snapshot: this.args.name,
body: {},
body: {
indices: "*",
include_global_state: false,
partial: false,
},
};

const response = await esClient.snapshot.create(esRequest);
Expand Down
47 changes: 47 additions & 0 deletions src/commands/es/snapshot/restore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { flags } from "@oclif/command";
import { Client } from "@elastic/elasticsearch";

import { Kommand } from "../../../common";

export default class EsSnapshotsRestore extends Kommand {
static initSdk = false;

static description = "Restore a snapshot repository inside an ES instance";

static flags = {
node: flags.string({
char: "n",
description: "Elasticsearch server URL",
default: "http://localhost:9200",
}),
help: flags.help(),
};

static args = [
{ name: "repository", description: "ES repository name", required: true },
{ name: "name", description: "ES snapshot name", required: true },
];

async runSafe() {
const esClient = new Client({ node: this.flags.node });

await esClient.indices.close({
index: "*",
expand_wildcards: "all",
});

const esRequest = {
repository: this.args.repository,
snapshot: this.args.name,
body: {
feature_states: ["none"],
include_global_state: false,
indices: "*",
},
};

const response = await esClient.snapshot.restore(esRequest);

this.logOk(`Success ${JSON.stringify(response.body)}`);
}
}
Loading