Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions plugins/data_migration/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ function trim_ending_slashes(address) {
return true;
}

if (!params.qstring.only_export || parseInt(params.qstring.only_export) !== 1) {
if (!params.qstring.only_export || (parseInt(params.qstring.only_export) !== 1 && parseInt(params.qstring.only_export) !== 2)) {
params.qstring.only_export = false;
if (!params.qstring.server_token || params.qstring.server_token === '') {
common.returnMessage(params, 404, 'data-migration.token_missing');
Expand All @@ -789,6 +789,9 @@ function trim_ending_slashes(address) {
}
}
else {
if (params.qstring.only_export && parseInt(params.qstring.only_export, 10) === 2) {
params.qstring.only_commands = true;
}
params.qstring.only_export = true;
params.qstring.server_address = "";
params.qstring.server_token = "";
Expand All @@ -811,16 +814,30 @@ function trim_ending_slashes(address) {


var data_migrator = new migration_helper();

data_migrator.export_data(apps, params, common.db, log).then(
function(result) {
common.returnMessage(params, 200, result);
},
function(error) {
common.returnMessage(params, 404, error.message);
}

);
if (params.qstring.only_commands) {
data_migrator.create_export_commands(apps, params, common.db, log).then(
function(result) {
//convert string to buffer
if (typeof result === "string") {
result = Buffer.from(result, 'utf8');
}
common.returnRaw(params, 200, result, {'Content-Type': 'text/plain; charset=utf-8', 'Content-disposition': 'attachment; filename=countly-export-commands.log'});
},
function(error) {
common.returnMessage(params, 404, error.message);
}
);
}
else {
data_migrator.export_data(apps, params, common.db, log).then(
function(result) {
common.returnMessage(params, 200, result);
},
function(error) {
common.returnMessage(params, 404, error.message);
}
);
}

});
return true;
Expand Down
56 changes: 55 additions & 1 deletion plugins/data_migration/api/data_migration_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ module.exports = function(my_db) {
}
}
//new data
scripts.push({cmd: 'mongodump', args: [...data.dbargs, '--collection', "events_data", '-q', '{ "_id": {"$in":{"$regex":"^' + data.appid + '_.*"}}}}', '--out', data.my_folder]});
scripts.push({cmd: 'mongodump', args: [...data.dbargs, '--collection', "events_data", '-q', '{ "_id": {"$regex":"^' + data.appid + '_.*"}}', '--out', data.my_folder]});
if (plugins.isPluginEnabled('drill')) {
scripts.push({cmd: 'mongodump', args: [...data.dbargs_drill, '--collection', "drill_events", '-q', '{ "a": "' + data.appid + '"}', '--out', data.my_folder]});
}
Expand Down Expand Up @@ -1145,6 +1145,60 @@ module.exports = function(my_db) {
this.update_progress = function(my_exportid, step, status, dif, reason, reset_progress, more_fields) {
update_progress(my_exportid, step, status, dif, reason, reset_progress, more_fields);
};

this.create_export_commands = function(apps, my_params, passed_db, passed_log) {
return new Promise(function(resolve, reject) {
if (passed_db) {
db = passed_db;
}
if (my_params) {
params = my_params;
}
if (passed_log) {
log = passed_log;
}

apps = apps.sort();
//clear out duplicates
for (let i = 1; i < apps.length - 1; i++) {
if (apps[i - 1] === apps[i]) {
apps.splice(i, 1); i--;
}
}

var scriptobj = [];
exportid = crypto.createHash('SHA1').update(JSON.stringify(apps)).digest('hex');
var my_folder = path.resolve(__dirname, './../export/' + exportid);
var image_folder = path.resolve(my_folder, './countly_app_icons');
for (let i = 0; i < apps.length; i++) {
let subfolder = path.resolve(my_folder, './' + apps[i]);
scriptobj.push({appid: apps[i], my_folder: subfolder, image_folder: image_folder, additional_files: path.resolve(my_folder, './countly_symbolication_files')});
}


Promise.all(scriptobj.map(create_export_scripts)).then(function(result) {
var lines = [];
if (result && Array.isArray(result)) {
for (var i = 0; i < result.length; i++) {
if (Array.isArray(result[i]) && result[i].length > 0) {
for (let j = 0; j < result[i].length; j++) {
lines.push(result[i][j].cmd + " '" + result[i][j].args.join("' '") + "'");
}
}
}
}
var data = lines.join("\n");
//save document in gridfs
resolve(data);


}).catch(function(err) {
log.e(err);
reject(Error(err.message));
});
});

};
this.export_data = function(apps, my_params, passed_db, passed_log) {
return new Promise(function(resolve, reject) {
if (passed_db) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,12 @@
data: exportData,
success: function(json) {
if (callback) {
callback({result: "success", data: json.result});
if (json.result) {
callback({result: "success", data: json.result});
}
else {
callback({result: "success", data: json});
}
}
},
error: function(xhr, status, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,27 @@

countlyDataMigration.saveExport(requestData, function(res) {
if (res.result === "success") {
CountlyHelpers.notify({
type: 'success',
message: CV.i18n('data-migration.export-started')
});
if (requestData.only_export === 2) {
Comment thread
Cookiezaurs marked this conversation as resolved.
var data = res.data;
//pack data and download
var blob = new Blob([data], { type: 'application/x-sh' });
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = 'export_commands.sh';
document.body.appendChild(a);
a.click();
CountlyHelpers.notify({
type: 'success',
message: CV.i18n('data-migration.download-auto')
});
}
else {
CountlyHelpers.notify({
type: 'success',
message: CV.i18n('data-migration.export-started')
});
}
}
else {
CountlyHelpers.notify({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ data-migration.export-other-path = Export folder:
data-migration.export-additional-files = Export crash symbols
data-migration.redirect-traffic = Redirect traffic to new server after migration is completed
data-migration.export-completed-unable-to-delete = Export completed. Unable to delete files
data-migration.export-type-get-export-scripts = Get only database export commands
data-migration.download-auto = Your download will start automatically.
#import data form
data-migration.import-title = Import data
data-migration.import-type = Import type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
</span>
</div>
</el-radio>
<el-radio class="data-migration__drawer__export-radio-item bu-is-flex bu-mt-3" :label="2" border>
<div class="data-migration__drawer__radio-label">
<span>
{{ i18n('data-migration.export-type-get-export-scripts') }}
</span>
</div>
</el-radio>
</el-radio-group>
</div>
</div>
Expand Down
Loading
Loading