diff --git a/README.md b/README.md index 80208219..0465a26f 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ $ npm install -g kourou $ kourou COMMAND running command... $ kourou (-v|--version|version) -kourou/0.28.0 darwin-arm64 node-v20.10.0 +kourou/0.28.1 darwin-arm64 node-v20.10.0 $ kourou --help [COMMAND] USAGE $ kourou COMMAND @@ -149,6 +149,7 @@ All other arguments and options will be passed as-is to the `sdk:query` method. * [`kourou es:snapshot:create REPOSITORY NAME`](#kourou-essnapshotcreate-repository-name) * [`kourou es:snapshot:create-repository REPOSITORY LOCATION`](#kourou-essnapshotcreate-repository-repository-location) * [`kourou es:snapshot:list REPOSITORY`](#kourou-essnapshotlist-repository) +* [`kourou es:snapshot:restore REPOSITORY NAME`](#kourou-essnapshotrestore-repository-name) * [`kourou file:decrypt FILE`](#kourou-filedecrypt-file) * [`kourou file:encrypt FILE`](#kourou-fileencrypt-file) * [`kourou file:test FILE`](#kourou-filetest-file) @@ -795,6 +796,23 @@ OPTIONS _See code: [lib/commands/es/snapshot/list.js](lib/commands/es/snapshot/list.js)_ +## `kourou es:snapshot:restore REPOSITORY NAME` + +Restore a snapshot repository inside an ES instance + +``` +USAGE + $ kourou es:snapshot:restore REPOSITORY NAME + +ARGUMENTS + REPOSITORY ES repository name + NAME ES snapshot name + +OPTIONS + -n, --node=node [default: http://localhost:9200] Elasticsearch server URL + --help show CLI help +``` + ## `kourou file:decrypt FILE` Decrypts an encrypted file. diff --git a/features/Elasticsearch.feature b/features/Z_Elasticsearch.feature similarity index 86% rename from features/Elasticsearch.feature rename to features/Z_Elasticsearch.feature index 8d99763f..d684c325 100644 --- a/features/Elasticsearch.feature +++ b/features/Z_Elasticsearch.feature @@ -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" | @@ -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" diff --git a/package-lock.json b/package-lock.json index f66df273..bb8b0065 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "kourou", - "version": "0.28.0", + "version": "0.28.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "kourou", - "version": "0.28.0", + "version": "0.28.1", "license": "Apache-2.0", "dependencies": { "@elastic/elasticsearch": "^7.12.0", diff --git a/package.json b/package.json index 82963ad3..a2eb9e89 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "kourou", "description": "The CLI that helps you manage your Kuzzle instances", - "version": "0.28.0", + "version": "0.28.1", "author": "The Kuzzle Team ", "bin": { "kourou": "./bin/run" diff --git a/src/commands/es/snapshot/create.ts b/src/commands/es/snapshot/create.ts index 6041abd1..ef9c635f 100644 --- a/src/commands/es/snapshot/create.ts +++ b/src/commands/es/snapshot/create.ts @@ -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); diff --git a/src/commands/es/snapshot/restore.ts b/src/commands/es/snapshot/restore.ts new file mode 100644 index 00000000..749e49b3 --- /dev/null +++ b/src/commands/es/snapshot/restore.ts @@ -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)}`); + } +}