Skip to content

Commit

Permalink
Add restore command inside kourou
Browse files Browse the repository at this point in the history
  • Loading branch information
rolljee committed Jan 24, 2024
1 parent c0cb9da commit ff16d1a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions features/Elasticsearch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ Feature: Elasticsearch commands
| 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"

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"
Expand Down
42 changes: 42 additions & 0 deletions src/commands/es/snapshot/restore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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 });

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

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

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

0 comments on commit ff16d1a

Please sign in to comment.