@iobroker/db-objects-jsonl
Advanced tools
Comparing version 4.0.0-alpha.31-20211221-5d2e6cde to 4.0.0-alpha.32-20211225-2bedca92
/** | ||
* Object DB in memory - Server | ||
* | ||
* Copyright 2013-2020 bluefox <dogafox@gmail.com> | ||
* Copyright 2013-2021 bluefox <dogafox@gmail.com> | ||
* | ||
@@ -19,2 +19,4 @@ * MIT License | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
@@ -32,4 +34,6 @@ /** | ||
}; | ||
super(settings); | ||
/** @type {import("@alcalzone/jsonl-db").JsonlDBOptions<any>} */ | ||
const jsonlOptions = { | ||
const jsonlOptions = this.settings.connection.jsonlOptions || { | ||
autoCompress: { | ||
@@ -46,6 +50,4 @@ sizeFactor: 2, | ||
settings.jsonlDB = { | ||
fileName: 'objects.jsonl', | ||
options: jsonlOptions | ||
fileName: 'objects.jsonl' | ||
}; | ||
super(settings); | ||
@@ -94,2 +96,8 @@ /** @type {JsonlDB<any>} */ | ||
}); | ||
if (this.settings.backup && this.settings.backup.period && !this.settings.backup.disabled) { | ||
this._backupInterval = setInterval(() => { | ||
this.saveBackup(); | ||
}, this.settings.backup.period); | ||
} | ||
} | ||
@@ -101,2 +109,37 @@ | ||
// Is regularly called and stores a compressed backup of the DB | ||
async saveBackup() { | ||
const now = Date.now(); | ||
const tmpBackupFileName = path.join(os.tmpdir(), this.getTimeStr(now) + '_' + this.settings.jsonlDB.fileName); | ||
const backupFileName = path.join( | ||
this.backupDir, | ||
this.getTimeStr(now) + '_' + this.settings.jsonlDB.fileName + '.gz' | ||
); | ||
try { | ||
if (fs.existsSync(backupFileName)) { | ||
return; | ||
} | ||
// Create a DB dump | ||
await this._db.dump(tmpBackupFileName); | ||
// and zip it | ||
const zlib = require('zlib'); | ||
const input = fs.createReadStream(tmpBackupFileName); | ||
const output = fs.createWriteStream(backupFileName); | ||
output.on('error', err => { | ||
this.log.error(`${this.namespace} Cannot save ${this.datasetName}: ${err}`); | ||
}); | ||
const compress = zlib.createGzip(); | ||
input.pipe(compress).pipe(output); | ||
fs.unlinkSync(tmpBackupFileName); | ||
// analyse older files | ||
this.deleteOldBackupFiles(this.settings.jsonlDB.fileName); | ||
} catch (e) { | ||
this.log.error(`${this.namespace} Cannot save backup ${backupFileName}: ${e.message}`); | ||
} | ||
} | ||
async destroy() { | ||
@@ -106,2 +149,5 @@ if (this._db) { | ||
} | ||
if (this._backupInterval) { | ||
clearInterval(this._backupInterval); | ||
} | ||
} | ||
@@ -108,0 +154,0 @@ } |
/** | ||
* States DB in memory - Server with Redis protocol | ||
* | ||
* Copyright 2013-2020 bluefox <dogafox@gmail.com> | ||
* Copyright 2013-2021 bluefox <dogafox@gmail.com> | ||
* | ||
@@ -6,0 +6,0 @@ * MIT License |
{ | ||
"name": "@iobroker/db-objects-jsonl", | ||
"version": "4.0.0-alpha.31-20211221-5d2e6cde", | ||
"version": "4.0.0-alpha.32-20211225-2bedca92", | ||
"engines": { | ||
@@ -8,6 +8,6 @@ "node": ">=12.0.0" | ||
"dependencies": { | ||
"@alcalzone/jsonl-db": "^2.2.0", | ||
"@iobroker/db-base": "4.0.0-alpha.31-20211221-5d2e6cde", | ||
"@iobroker/db-objects-file": "4.0.0-alpha.31-20211221-5d2e6cde", | ||
"@iobroker/db-objects-redis": "4.0.0-alpha.31-20211221-5d2e6cde", | ||
"@alcalzone/jsonl-db": "~2.3.0", | ||
"@iobroker/db-base": "4.0.0-alpha.32-20211225-2bedca92", | ||
"@iobroker/db-objects-file": "4.0.0-alpha.32-20211225-2bedca92", | ||
"@iobroker/db-objects-redis": "4.0.0-alpha.32-20211225-2bedca92", | ||
"deep-clone": "^3.0.3", | ||
@@ -42,3 +42,3 @@ "fs-extra": "^10.0.0", | ||
], | ||
"gitHead": "1360216c252693f9f7ed38e1ef385a5f4a4692d4" | ||
"gitHead": "8bb1199a14b696c069bf84f3b88147aa23e61a31" | ||
} |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
58656
1097
2
+ Added@alcalzone/jsonl-db@2.3.0(transitive)
+ Added@iobroker/db-base@4.0.0-alpha.32-20211225-2bedca92(transitive)
+ Added@iobroker/db-objects-file@4.0.0-alpha.32-20211225-2bedca92(transitive)
+ Added@iobroker/db-objects-redis@4.0.0-alpha.32-20211225-2bedca92(transitive)
+ Added@iobroker/js-controller-common@4.0.0-alpha.32-20211225-2bedca92(transitive)
+ Addedproper-lockfile@4.1.2(transitive)
- Removed@alcalzone/jsonl-db@2.5.3(transitive)
- Removed@alcalzone/proper-lockfile@4.1.3-0(transitive)
- Removed@iobroker/db-base@4.0.0-alpha.31-20211221-5d2e6cde(transitive)
- Removed@iobroker/db-objects-file@4.0.0-alpha.31-20211221-5d2e6cde(transitive)
- Removed@iobroker/db-objects-redis@4.0.0-alpha.31-20211221-5d2e6cde(transitive)
- Removed@iobroker/js-controller-common@4.0.0-alpha.31-20211221-5d2e6cde(transitive)
Updated@alcalzone/jsonl-db@~2.3.0
Updated@iobroker/db-objects-file@4.0.0-alpha.32-20211225-2bedca92
Updated@iobroker/db-objects-redis@4.0.0-alpha.32-20211225-2bedca92