Compare commits
11 Commits
b90cba5c71
...
master
Author | SHA1 | Date | |
---|---|---|---|
33e7b7acfa | |||
f27193163d | |||
bde8bc99b1 | |||
6ef33b6294 | |||
80a2aafa72 | |||
00b886740d | |||
62a8da129a | |||
90a0060f56 | |||
12eafe82ce | |||
7d474b8f87 | |||
a4929c86c5 |
15
.eslintrc.json
Normal file
15
.eslintrc.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"commonjs": true,
|
||||||
|
"es2021": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"google"
|
||||||
|
],
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": "latest"
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
}
|
||||||
|
}
|
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"editor.codeActionsOnSave": {
|
||||||
|
"source.fixAll.eslint": true
|
||||||
|
},
|
||||||
|
"eslint.validate": ["javascript"]
|
||||||
|
}
|
@@ -7,7 +7,7 @@ This branch is a rewrite of the [previous in Java Developed branch](https://git.
|
|||||||
### Requirements
|
### Requirements
|
||||||
- NodeJS >= 14
|
- NodeJS >= 14
|
||||||
|
|
||||||
You can either: [Build a executeable](#build-a-executeable) or [Runing from Source](#running-from-source)
|
You can either: [Build a executeable](#build-a-executeable) or [Running from Source](#running-from-source)
|
||||||
|
|
||||||
### Build a executeable
|
### Build a executeable
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ pnpm run pkg
|
|||||||
yarn run pkg
|
yarn run pkg
|
||||||
```
|
```
|
||||||
|
|
||||||
Your builded binary executeable should be in bin/
|
Your builded binary executeable should be located in `bin/`
|
||||||
|
|
||||||
### Running from Source
|
### Running from Source
|
||||||
|
|
||||||
|
136
archiver.js
136
archiver.js
@@ -1,77 +1,79 @@
|
|||||||
|
/* eslint-disable require-jsdoc */
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { EventEmitter } = require('events');
|
const {EventEmitter} = require('events');
|
||||||
|
|
||||||
class Archiver {
|
class Archiver {
|
||||||
constructor(backupPath, backupPaths) {
|
constructor(backupPath, backupPaths, gzip, gzipLevel) {
|
||||||
this.backupPath = backupPath;
|
this.backupPath = backupPath;
|
||||||
this.backupPaths = backupPaths;
|
this.backupPaths = backupPaths;
|
||||||
this.eventEmitter = new EventEmitter();
|
this.eventEmitter = new EventEmitter();
|
||||||
this.archive = require('archiver')('tar', {
|
this.archive = require('archiver')('tar', {
|
||||||
zlib: { level: 9 }
|
gzip: gzip,
|
||||||
});
|
gzipOptions: {level: gzipLevel},
|
||||||
this.totalFiles = 0;
|
});
|
||||||
|
this.totalFiles = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
const EVENT_EMITTER = this.eventEmitter;
|
||||||
|
const ARCHIVE_LOCATION = path.join(this.backupPath);
|
||||||
|
const OUTPUT = fs.createWriteStream(ARCHIVE_LOCATION);
|
||||||
|
|
||||||
|
OUTPUT.on('close', function() {
|
||||||
|
EVENT_EMITTER.emit('finish');
|
||||||
|
});
|
||||||
|
|
||||||
|
OUTPUT.on('end', function() {
|
||||||
|
console.log('Data has been drained');
|
||||||
|
});
|
||||||
|
|
||||||
|
this.archive.on('warning', function(err) {
|
||||||
|
if (err.code === 'ENOENT') console.log(err);
|
||||||
|
else throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.archive.on('error', function(err) {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.archive.on('progress', function(progressInfo) {
|
||||||
|
EVENT_EMITTER.emit('progress', progressInfo);
|
||||||
|
});
|
||||||
|
|
||||||
|
// pipe archive data to the file
|
||||||
|
this.archive.pipe(OUTPUT);
|
||||||
|
|
||||||
|
for (const ITEM of this.backupPaths) {
|
||||||
|
if (!fs.existsSync(ITEM)) continue;
|
||||||
|
const IS_DIR = fs.lstatSync(ITEM).isDirectory();
|
||||||
|
if (IS_DIR) {
|
||||||
|
this.archive.directory(ITEM, path.basename(ITEM));
|
||||||
|
const COUNTED = require('count-files-dirs').countSync(ITEM);
|
||||||
|
this.totalFiles += COUNTED.fileCount + COUNTED.dirCount;
|
||||||
|
} else {
|
||||||
|
this.archive.file(ITEM, {name: path.basename(ITEM)});
|
||||||
|
this.totalFiles++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
start() {
|
add(item) {
|
||||||
const EVENT_EMITTER = this.eventEmitter;
|
if (!fs.existsSync(item)) return;
|
||||||
const ARCHIVE_LOCATION = path.join(this.backupPath);
|
const IS_DIR = fs.lstatSync(item).isDirectory();
|
||||||
const OUTPUT = fs.createWriteStream(ARCHIVE_LOCATION);
|
if (IS_DIR) {
|
||||||
|
this.archive.directory(item, path.basename(item));
|
||||||
OUTPUT.on('close', function () {
|
const COUNTED = require('count-files-dirs').countSync(item);
|
||||||
EVENT_EMITTER.emit('finish');
|
this.totalFiles += COUNTED.fileCount + COUNTED.dirCount;
|
||||||
});
|
} else {
|
||||||
|
this.archive.file(item, {name: path.basename(item)});
|
||||||
OUTPUT.on('end', function () {
|
this.totalFiles++;
|
||||||
console.log('Data has been drained');
|
|
||||||
});
|
|
||||||
|
|
||||||
this.archive.on('warning', function (err) {
|
|
||||||
if (err.code === 'ENOENT') console.log(err);
|
|
||||||
else throw err;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.archive.on('error', function (err) {
|
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.archive.on('progress', function (progressInfo) {
|
|
||||||
EVENT_EMITTER.emit('progress', progressInfo);
|
|
||||||
});
|
|
||||||
|
|
||||||
// pipe archive data to the file
|
|
||||||
this.archive.pipe(OUTPUT);
|
|
||||||
|
|
||||||
for (const ITEM of this.backupPaths) {
|
|
||||||
if (!fs.existsSync(ITEM)) continue;
|
|
||||||
const IS_DIR = fs.lstatSync(ITEM).isDirectory();
|
|
||||||
if (IS_DIR) {
|
|
||||||
this.archive.directory(ITEM, path.basename(ITEM));
|
|
||||||
const COUNTED = require('count-files-dirs').countSync(ITEM);
|
|
||||||
this.totalFiles += COUNTED.fileCount + COUNTED.dirCount;
|
|
||||||
} else {
|
|
||||||
this.archive.file(ITEM, { name: path.basename(ITEM) });
|
|
||||||
this.totalFiles++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
add(item) {
|
pack() {
|
||||||
if (!fs.existsSync(item)) return;
|
this.archive.finalize();
|
||||||
const IS_DIR = fs.lstatSync(item).isDirectory();
|
}
|
||||||
if (IS_DIR) {
|
|
||||||
this.archive.directory(item, path.basename(item));
|
|
||||||
const COUNTED = require('count-files-dirs').countSync(item);
|
|
||||||
this.totalFiles += COUNTED.fileCount + COUNTED.dirCount;
|
|
||||||
} else {
|
|
||||||
this.archive.file(item, { name: path.basename(item) });
|
|
||||||
this.totalFiles++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pack() {
|
|
||||||
this.archive.finalize();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Archiver;
|
module.exports = Archiver;
|
||||||
|
26
logger.js
26
logger.js
@@ -1,17 +1,17 @@
|
|||||||
const ansiColors = require('ansi-colors');
|
const ansiColors = require('ansi-colors');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
info(message) {
|
info(message) {
|
||||||
console.log(ansiColors.bold.blue("🛈") + " " + ansiColors.bold(message));
|
console.log(ansiColors.bold.blue('🛈') + ' ' + ansiColors.bold(message));
|
||||||
},
|
},
|
||||||
warn(message) {
|
warn(message) {
|
||||||
console.log(ansiColors.bold.yellow("⚠") + " " + ansiColors.bold(message));
|
console.log(ansiColors.bold.yellow('⚠') + ' ' + ansiColors.bold(message));
|
||||||
},
|
},
|
||||||
error(message) {
|
error(message) {
|
||||||
console.log(ansiColors.red.red("✖") + " " + ansiColors.bold(message));
|
console.log(ansiColors.red.red('✖') + ' ' + ansiColors.bold(message));
|
||||||
},
|
},
|
||||||
success(message) {
|
success(message) {
|
||||||
console.log(ansiColors.green("✔") + " " + ansiColors.bold(message));
|
console.log(ansiColors.green('✔') + ' ' + ansiColors.bold(message));
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
|
17
package.json
17
package.json
@@ -14,6 +14,8 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"eslint": ">=5.16.0",
|
||||||
|
"eslint-config-google": "^0.14.0",
|
||||||
"pkg": "^5.8.0"
|
"pkg": "^5.8.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -21,12 +23,25 @@
|
|||||||
"ansi-colors": "^4.1.3",
|
"ansi-colors": "^4.1.3",
|
||||||
"archiver": "^5.3.1",
|
"archiver": "^5.3.1",
|
||||||
"count-files-dirs": "^0.2.3",
|
"count-files-dirs": "^0.2.3",
|
||||||
|
"crontab": "^1.4.2",
|
||||||
|
"fs-extra": "^10.1.0",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
"mysqldump": "^3.2.0",
|
"mysqldump": "^3.2.0",
|
||||||
"ora": "5.4.1",
|
"ora": "5.4.1",
|
||||||
"prettytime": "^1.0.0",
|
"prettytime": "^1.0.0",
|
||||||
"prompts": "^2.4.2",
|
"prompts": "^2.4.2",
|
||||||
"recursive-readdir": "^2.2.2",
|
|
||||||
"tiny-glob": "^0.2.9"
|
"tiny-glob": "^0.2.9"
|
||||||
|
},
|
||||||
|
"pnpm": {
|
||||||
|
"overrides": {
|
||||||
|
"minimist@<1.2.6": ">=1.2.6",
|
||||||
|
"braces@<2.3.1": ">=2.3.1",
|
||||||
|
"diff@<3.5.0": ">=3.5.0",
|
||||||
|
"minimatch@<3.0.2": ">=3.0.2",
|
||||||
|
"debug@<2.6.9": ">=2.6.9",
|
||||||
|
"minimist@<0.2.1": ">=0.2.1",
|
||||||
|
"glob-parent@<5.1.2": ">=5.1.2",
|
||||||
|
"growl@<1.10.0": ">=1.10.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
20
timer.js
20
timer.js
@@ -1,14 +1,14 @@
|
|||||||
const prettytime = require('prettytime')
|
/* eslint-disable require-jsdoc */
|
||||||
|
const prettytime = require('prettytime');
|
||||||
class Timer {
|
class Timer {
|
||||||
startTimer() {
|
startTimer() {
|
||||||
this.start = Date.now();
|
this.start = Date.now();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
endTimer() {
|
endTimer() {
|
||||||
const ELAPSED = Date.now() - this.start;
|
return prettytime(Date.now() - this.start, {decimals: 2});
|
||||||
return prettytime(ELAPSED, { decimals: 2 });
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Timer;
|
module.exports = Timer;
|
||||||
|
Reference in New Issue
Block a user