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
24 changes: 13 additions & 11 deletions api/parts/mgmt/app_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,10 @@ usersApi.deleteExport = function(filename, params, callback) {
}
};

var run_command = function(my_command) {
var run_command = function(my_command, my_args) {
return new Promise(function(resolve, reject) {
var child = spawn(my_command, {
shell: true,
var child = spawn(my_command, my_args, {
shell: false,
cwd: path.resolve(__dirname, './../../../export/AppUser'),
detached: false
}, function(error) {
Expand Down Expand Up @@ -615,7 +615,7 @@ var run_command = function(my_command) {
};
var clear_out_empty_files = function(folder) {
return new Promise(function(resolve) {
run_command("find " + folder + " -type f -name '*.json' -size 0 -delete").then(
run_command("find", [folder, "-type", "f", "-name", "*.json", "-size", "0", "-delete"]).then(
function() {
resolve();
},
Expand Down Expand Up @@ -727,11 +727,12 @@ usersApi.export = function(app_id, query, params, callback) {
}
var export_filename = 'appUser_' + app_id + '_' + eid;

var dbstr = "";
var dbargs = [];
var export_commands = {};
var db_params = plugins.getDbConnectionParams('countly');
for (var p in db_params) {
dbstr += " --" + p + " " + db_params[p];
dbargs.push("--" + p);
dbargs.push(db_params[p]);
}

plugins.dispatch("/systemlogs", {
Expand Down Expand Up @@ -763,16 +764,17 @@ usersApi.export = function(app_id, query, params, callback) {
}
}).then(function() {
//export data from metric_changes
return run_command('mongoexport ' + dbstr + ' --collection metric_changes' + app_id + ' -q \'{uid:{$in: ["' + res[0].uid.join('","') + '"]}}\' --out ' + export_folder + '/metric_changes' + app_id + '.json');
return run_command('mongoexport', [...dbargs, "--collection", "metric_changes" + app_id, "-q", '{uid:{$in: ["' + res[0].uid.join('","') + '"]}}', "--out", export_folder + "/metric_changes" + app_id + ".json"]);
}).then(function() {
//export data from app_users
return run_command('mongoexport ' + dbstr + ' --collection app_users' + app_id + ' -q \'{uid: {$in: ["' + res[0].uid.join('","') + '"]}}\' --out ' + export_folder + '/app_users' + app_id + '.json');
return run_command('mongoexport', [...dbargs, "--collection", "app_users" + app_id, "-q", '{uid:{$in: ["' + res[0].uid.join('","') + '"]}}', "--out", export_folder + "/app_users" + app_id + ".json"]);
}).then(
function() {
//get other export commands from other plugins
plugins.dispatch("/i/app_users/export", {
app_id: app_id,
dbstr: dbstr,
dbstr: "",
dbargs: dbargs,
export_commands: export_commands,
query: query,
uids: res[0].uid,
Expand All @@ -781,15 +783,15 @@ usersApi.export = function(app_id, query, params, callback) {
var commands = [];
for (var prop in export_commands) {
for (let k = 0; k < export_commands[prop].length; k++) {
commands.push(run_command(export_commands[prop][k]));
commands.push(run_command(export_commands[prop][k].cmd, export_commands[prop][k].args));
}
}
Promise.all(commands).then(
function() {
//pack export
clear_out_empty_files(path.resolve(__dirname, './../../../export/AppUser/' + export_filename))//remove empty files
.then(function() {
return run_command("tar -zcvf " + export_filename + ".tar.gz" + " " + export_filename);
return run_command("tar", ["-zcvf", export_filename + ".tar.gz", export_filename]);
}) //create archive
.then(function() {
return new Promise(function(resolve, reject) { /*save export in gridFS*/
Expand Down
4 changes: 2 additions & 2 deletions plugins/crashes/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ plugins.setConfigs("crashes", {
if (!ob.export_commands.crashes) {
ob.export_commands.crashes = [];
}
ob.export_commands.crashes.push('mongoexport ' + ob.dbstr + ' --collection app_crashes' + ob.app_id + ' -q \'{uid:{$in: ["' + uids.join('","') + '"]}}\' --out ' + ob.export_folder + '/crashes' + ob.app_id + '.json');
ob.export_commands.crashes.push('mongoexport ' + ob.dbstr + ' --collection app_crashusers' + ob.app_id + ' -q \'{uid:{$in: ["' + uids.join('","') + '"]}}\' --out ' + ob.export_folder + '/crashusers' + ob.app_id + '.json');
ob.export_commands.crashes.push({cmd: 'mongoexport', args: [...ob.dbargs, '--collection', 'app_crashes' + ob.app_id, '-q', '{uid:{$in: ["' + uids.join('","') + '"]}}', '--out', ob.export_folder + '/crashes' + ob.app_id + '.json']});
ob.export_commands.crashes.push({cmd: 'mongoexport', args: [...ob.dbargs, '--collection', 'app_crashusers' + ob.app_id, '-q', '{uid:{$in: ["' + uids.join('","') + '"]}}', '--out', ob.export_folder + '/crashusers' + ob.app_id + '.json']});
resolve();
}
});
Expand Down
Loading