Skip to content

Instantly share code, notes, and snippets.

@godber
Last active October 12, 2018 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save godber/9a234569727b10d5b33d8e12ead8d95a to your computer and use it in GitHub Desktop.
Save godber/9a234569727b10d5b33d8e12ead8d95a to your computer and use it in GitHub Desktop.
Teraslice dump_asset
'use strict';
const argv = require('yargs').argv;
const fse = require('fs-extra');
var elasticsearch = require('elasticsearch');
function saveAsset(assetName, assetVersion, binaryData) {
const newPath = `${assetName}/${assetVersion}`;
const tempFileName = `${newPath}/asset.zip`;
return fse.mkdirp(newPath)
.then(() => fse.writeFile(tempFileName, binaryData))
.catch((err) => {
console.log(err);
});
}
async function main(esCluster, indexName, assetName) {
var client = new elasticsearch.Client({
host: esCluster,
// log: 'trace',
});
const response = await client.search({
index: indexName,
body: {
query: {
term: {name: assetName},
},
},
});
for (const asset of response.hits.hits) {
console.log(`asset:, ${asset._source.name}, ${asset._source.version}`);
const binaryData = Buffer.from(asset._source.blob, 'base64');
try {
await saveAsset(asset._source.name, asset._source.version, binaryData);
} catch (e) {
console.log(`ouch ${e}`);
}
}
}
main(argv.cluster, argv.index, argv.asset);
{
"name": "dump-assets",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"elasticsearch": "^15.1.1",
"fs-extra": "^7.0.0",
"yargs": "^12.0.2"
}
}
@godber
Copy link
Author

godber commented Oct 12, 2018

Call with:

node ./index.js --cluster localhost:9200 --index teraslice-cluster1__assets --asset my_teraslice_asset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment