add option to enable gzip and set level
This commit is contained in:
parent
c23c09441f
commit
a4929c86c5
|
@ -3,12 +3,13 @@ const path = require('path');
|
|||
const { EventEmitter } = require('events');
|
||||
|
||||
class Archiver {
|
||||
constructor(backupPath, backupPaths) {
|
||||
constructor(backupPath, backupPaths, gzip, gzipLevel) {
|
||||
this.backupPath = backupPath;
|
||||
this.backupPaths = backupPaths;
|
||||
this.eventEmitter = new EventEmitter();
|
||||
this.archive = require('archiver')('tar', {
|
||||
zlib: { level: 9 }
|
||||
gzip: gzip,
|
||||
gzipOptions: { level: gzipLevel }
|
||||
});
|
||||
this.totalFiles = 0;
|
||||
}
|
||||
|
|
20
index.js
20
index.js
|
@ -96,7 +96,11 @@ const run = async (programArgs) => {
|
|||
.replace("{taskName}", PATH.parse(taskName).name);
|
||||
|
||||
const DB_FILE = PATH.join(TEMP_DIR, require('crypto').randomBytes(16).toString('hex') + ".sql");
|
||||
const ARCHIVE = new BACKUP_ARCHIVE(PATH.join(BACKUPS_DIRECTORY, PATH.parse(taskName).name, REPLACED_FILENAME + ".tar.gz"), TASK_FILE_CONTENTS.filesystem.targets);
|
||||
const ARCHIVE = new BACKUP_ARCHIVE(PATH.join(BACKUPS_DIRECTORY, PATH.parse(taskName).name,
|
||||
REPLACED_FILENAME + ".tar.gz"),
|
||||
TASK_FILE_CONTENTS.filesystem.targets,
|
||||
TASK_FILE_CONTENTS.general.gzip,
|
||||
TASK_FILE_CONTENTS.general.gzipLevel);
|
||||
|
||||
ARCHIVE.eventEmitter.on('progress', (progressInfo) => {
|
||||
const TOTAL = ARCHIVE.totalFiles;
|
||||
|
@ -232,7 +236,9 @@ const run = async (programArgs) => {
|
|||
const TASK_CONFIG = {
|
||||
"general": {
|
||||
"dateFormat": "yyyy-MM-DD HH-mm-ss",
|
||||
"outputFile": "{date} - {taskName}"
|
||||
"outputFile": "{date} - {taskName}",
|
||||
"gzip": true,
|
||||
"gzipLevel": 6
|
||||
},
|
||||
"vacuum": {
|
||||
"enabled": true,
|
||||
|
@ -294,6 +300,16 @@ const validate = (taskConfig) => {
|
|||
} else {
|
||||
ERRORS.push("general.outputFile is not defined or is not a string");
|
||||
}
|
||||
if (typeof taskConfig.general.gzip === "boolean") {
|
||||
if (taskConfig.general.gzip) {
|
||||
if (!taskConfig.general.gzipLevel && typeof taskConfig.general.gzipLevel !== "number") {
|
||||
ERRORS.push("general.gzipLevel is not defined or is not a number");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ERRORS.push("general.gzip is not defined or is not a boolean");
|
||||
ERRORS.push("general.gzipLevel is not defined or is not a number");
|
||||
}
|
||||
} else {
|
||||
ERRORS.push("general section is missing or not an object");
|
||||
ERRORS.push("general.dateFormat is not defined or is not a string");
|
||||
|
|
Loading…
Reference in New Issue
Block a user