diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2020-01-12 02:54:24 -0500 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2020-01-12 02:54:24 -0500 |
commit | 9d17eb8923c0a0366b15d7b634f7229371d74286 (patch) | |
tree | 229e808c62c7c6d523509dc3dfa0bb2af69850d9 | |
parent | e6995511a36d5ced79e0738f06487bec592cb992 (diff) |
backup fixes
-rw-r--r-- | src/server/ApiManagers/SessionManager.ts | 13 | ||||
-rw-r--r-- | src/server/DashSession/DashSessionAgent.ts | 15 |
2 files changed, 12 insertions, 16 deletions
diff --git a/src/server/ApiManagers/SessionManager.ts b/src/server/ApiManagers/SessionManager.ts index 463dfc739..9bf0e4b50 100644 --- a/src/server/ApiManagers/SessionManager.ts +++ b/src/server/ApiManagers/SessionManager.ts @@ -28,16 +28,11 @@ export default class SessionManager extends ApiManager { register({ method: Method.GET, - subscription: this.secureSubscriber("debug", "mode?", "recipient?"), + subscription: this.secureSubscriber("debug", "to?"), secureHandler: this.authorizedAction(async ({ req: { params }, res }) => { - const mode = params.mode || "active"; - const recipient = params.recipient || DashSessionAgent.notificationRecipient; - if (!["passive", "active"].includes(mode)) { - res.send(`Your request failed. '${mode}' is not a valid mode: please choose either 'active' or 'passive'`); - } else { - const { error } = await sessionAgent.serverWorker.emitToMonitorPromise("debug", { mode, recipient }); - res.send(error ? error.message : `Your request was successful: the server ${mode === "active" ? "created and compressed a new" : "retrieved and compressed the most recent"} back up. It was sent to ${recipient}.`); - } + const to = params.to || DashSessionAgent.notificationRecipient; + const { error } = await sessionAgent.serverWorker.emitToMonitorPromise("debug", { to }); + res.send(error ? error.message : `Your request was successful: the server captured and compressed (but did not save) a new back up. It was sent to ${to}.`); }) }); diff --git a/src/server/DashSession/DashSessionAgent.ts b/src/server/DashSession/DashSessionAgent.ts index bf07cf89e..c55e01243 100644 --- a/src/server/DashSession/DashSessionAgent.ts +++ b/src/server/DashSession/DashSessionAgent.ts @@ -30,9 +30,9 @@ export class DashSessionAgent extends AppliedSessionAgent { monitor.addReplCommand("pull", [], () => monitor.exec("git pull")); monitor.addReplCommand("solr", [/start|stop|index/], this.executeSolrCommand); monitor.addReplCommand("backup", [], this.backup); - monitor.addReplCommand("debug", [/active|passive/, /\S+\@\S+/], async ([mode, recipient]) => this.dispatchZippedDebugBackup(mode, recipient)); + monitor.addReplCommand("debug", [/\S+\@\S+/], async ([to]) => this.dispatchZippedDebugBackup(to)); monitor.on("backup", this.backup); - monitor.on("debug", async ({ mode, recipient }) => this.dispatchZippedDebugBackup(mode, recipient)); + monitor.on("debug", async ({ to }) => this.dispatchZippedDebugBackup(to)); monitor.coreHooks.onCrashDetected(this.dispatchCrashReport); } @@ -164,14 +164,12 @@ export class DashSessionAgent extends AppliedSessionAgent { * @param mode specifies whether or not to make a new backup before exporting * @param to the recipient of the email */ - private async dispatchZippedDebugBackup(mode: string, to: string): Promise<void> { + private async dispatchZippedDebugBackup(to: string): Promise<void> { const { mainLog } = this.sessionMonitor; try { // if desired, complete an immediate backup to send - if (mode === "active") { - await this.backup(); - mainLog("backup complete"); - } + await this.backup(); + mainLog("backup complete"); const backupsDirectory = `${this.releaseDesktop}/backups`; @@ -201,6 +199,9 @@ export class DashSessionAgent extends AppliedSessionAgent { attachments: [{ filename: zipName, path: zipPath }] }); + // since this is intended to be a zero-footprint operation, clean up + // by unlinking both the backup generated earlier in the function and the compressed zip file. + // to generate a persistent backup, just run backup. unlinkSync(zipPath); rimraf.sync(targetPath); |