@live-change/backup-service 0.8.24 → 0.8.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/backup.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import App from '@live-change/framework'
2
2
  const app = App.app()
3
+ import definition from './definition.js'
4
+
3
5
  import fs from 'fs'
4
6
  import fse from 'fs-extra'
5
7
  import util from 'util'
package/clearEvents.js ADDED
@@ -0,0 +1,21 @@
1
+ import App from '@live-change/framework'
2
+ const app = App.app()
3
+ import definition from './definition.js'
4
+
5
+ export async function getLastEventId() {
6
+ if(app.splitEvents) {
7
+ throw new Error("getLastEventId not supported in split events mode")
8
+ } else {
9
+ const lastLogs = app.dao.get(['database', 'logRange', app.databaseName, 'events', { reverse: true, limit: 1 }])
10
+ const lastLog = lastLogs[0]
11
+ return lastLog?.id || ''
12
+ }
13
+ }
14
+
15
+ export async function removeOldEvents(before) {
16
+ if(app.splitEvents) {
17
+ throw new Error("removeOldEvents not supported in split events mode")
18
+ } else {
19
+ await app.dao.request(['database', 'clearLog'], app.databaseName, 'events', before)
20
+ }
21
+ }
package/index.js CHANGED
@@ -10,6 +10,7 @@ const expressApp = express()
10
10
  import fs from 'fs'
11
11
  import { createBackup, currentBackupPath, removeOldBackups } from './backup.js'
12
12
  import { restoreBackup } from './restore.js'
13
+ import { getLastEventId, removeOldEvents } from './clearEvents.js'
13
14
 
14
15
  import progress from "progress-stream"
15
16
 
@@ -46,14 +47,17 @@ if(Object.keys(users) > 0) {
46
47
  }
47
48
 
48
49
  function doBackup() {
50
+ console.log("DOING BACKUP!")
49
51
  if(currentBackup) return currentBackup
50
52
  const path = currentBackupPath(backupsDir)
51
53
  const filename = path.slice(path.lastIndexOf('/')+1)
52
54
  currentBackup = {
53
55
  path, filename,
54
56
  promise: queue.add(async () => {
55
- await removeOldBackups(backupsDir, 10*TWENTY_FOUR_HOURS, 10)
57
+ const lastEventId = await getLastEventId()
58
+ await removeOldBackups(backupsDir, 10 * TWENTY_FOUR_HOURS, 10)
56
59
  await createBackup(path)
60
+ if(config.clearEvents) await removeOldEvents(lastEventId)
57
61
  })
58
62
  }
59
63
  currentBackup.promise.then(done => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/backup-service",
3
- "version": "0.8.24",
3
+ "version": "0.8.26",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,14 +9,14 @@
9
9
  "author": "Michał Łaszczewski <michal@emikse.com>",
10
10
  "license": "BSD-3-Clause",
11
11
  "dependencies": {
12
- "@live-change/db-client": "^0.8.24",
13
- "@live-change/framework": "^0.8.24",
12
+ "@live-change/db-client": "^0.8.26",
13
+ "@live-change/framework": "^0.8.26",
14
14
  "express": "^4.18.2",
15
15
  "express-basic-auth": "^1.2.1",
16
16
  "fs-extra": "^11.1.1",
17
17
  "p-queue": "^7.3.4",
18
18
  "progress-stream": "^2.0.0"
19
19
  },
20
- "gitHead": "63e942caccbcb1c9bfbd1a3ef1d097124514c5a7",
20
+ "gitHead": "e62696aa9fa6e5b86312dfb64c97efa300d41147",
21
21
  "type": "module"
22
22
  }